Page MenuHomeFreeBSD

sys: add safe_read(9)
ClosedPublic

Authored by kib on Mar 29 2025, 5:18 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Jun 4, 1:46 AM
Unknown Object (File)
Wed, Jun 3, 1:31 PM
Unknown Object (File)
Sat, May 30, 9:50 PM
Unknown Object (File)
Fri, May 29, 11:23 PM
Unknown Object (File)
Fri, May 29, 12:55 AM
Unknown Object (File)
Thu, May 28, 12:03 PM
Unknown Object (File)
Wed, May 27, 8:30 PM
Unknown Object (File)
Wed, May 27, 6:28 PM

Details

Summary
amd64: extract uiomove_mem() from memrw()


The MD function with MI interface to provide a way to read arbitrary
(canonical) KVA.  amd64 only for now.

Tested by:      aokblast

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kib requested review of this revision.Mar 29 2025, 5:18 PM

Slightly different version, avoid the thread-private flag.

kib retitled this revision from safe_read to sys: add safe_read(9).
kib edited the summary of this revision. (Show Details)
kib added reviewers: emaste, markj, jhb.
sys/amd64/amd64/trap.c
797 ↗(On Diff #178476)

Maybe it should be formulated as if (__predict_false(!usermode && ...?

sys/sys/systm.h
557 ↗(On Diff #178476)
559 ↗(On Diff #178476)
kib marked 2 inline comments as done.Sat, May 23, 5:58 PM
kib added inline comments.
sys/amd64/amd64/trap.c
797 ↗(On Diff #178476)

I believe that the first check for tf_rip makes the shortest path through the condition: userspace must work hard to fault with this specific %rip, and kernel most likely would not fault on safe_read_read with other conditions false.

kib edited the summary of this revision. (Show Details)

Complete overhaul. Stop modifying page fault handler at all. Reuse code from mem.c.

sys/amd64/amd64/machdep.c
1868 ↗(On Diff #178524)

uio_rw is indeed used. uio_segflg too, if we end up calling uiomove().

kib marked an inline comment as done.

Fill uio_seg and uio_rw.

sys/amd64/amd64/machdep.c
1868 ↗(On Diff #178524)

IMO it would be better to explicitly initialize uio_td, either to curthread or NULL.

sys/amd64/amd64/uio_machdep.c
194

So with this check and the DMAP boundary check above, we can only use safe_read() to access the kernel map and direct map. Is that the intent?

kib marked an inline comment as done.Tue, May 26, 4:34 PM
kib added inline comments.
sys/amd64/amd64/uio_machdep.c
194

I believe it is enough for the use at hand, D46193.

More, returning to the 'faulting' implementation, I now think that it opened the access too wide, it should check at least that the address is in KVA. Of course we can return to the 'faulting' way of doing things for other addresses which cannot be handled by pmap_extract(kernel_pmap). I thought that avoiding adding a check to the page fault path is good.

I don't take a look at the code. But it works with KCFI.

This revision is now accepted and ready to land.Thu, May 28, 12:13 PM
This revision was automatically updated to reflect the committed changes.