Repository navigation
syscall: refuse kernel addresses from user space in a kernel build - #20412
Conversation
linguini1
left a comment
There was a problem hiding this comment.
Test logs required please.
|
|
Full QEMU |
|
comment in the original pr |
|
Pushed: uaccess_ok is access_ok now, and arm64 returns -EINVAL instead of panicking. Fresh logs in the body. |
|
Please include the full logs for each target |
|
@linguini1 arm64 and rv64 QEMU runs are in the description.
|
|
hey @linguini1 logs are up (comment + zip), mind another look when u got time? same for #20416 and #20417 |
|
hey @linguini1, reran everything on the current head (8e5bbca) since it got reworked after xiao's review
mind a re-review when u got a sec? |
|
Please ensure to add "Assisted-by" to your commit messages. |
@royzah please add the above line in your commit messsage. |
casaroli
left a comment
There was a problem hiding this comment.
Thanks for this. The base looks good and the arch split is clean.
I rebased it on master (c7cba68) and ran qemu-armv8a:knsh and qemu-armv8a:nsh; ostest exits 0 on both. rv-virt:knsh64 builds with no new warnings.
Two small things before it merges:
- Please add the
Assisted-bytrailer to each commit, as the guide asks. uaccess_fault()calls_exit(SIGSEGV), which ends the task with exit status 11, not a real SIGSEGV. The task still dies, but the name suggests a signal. A short comment, or raising the signal, would be clearer.
The riscv and x86_64 page-table walkers only have build coverage here; arm64 is the only one I could run. Because #20415 and #20418 use up_addrenv_va_to_pa() on those arches, a runtime check there would help later.
|
@royzah please fix style error: |
|
@casaroli Rebased and updated the PR body. |
Fixed |
Blank lines after declarations, one declaration per line and case alignment, so the check passes on the files the next commits change. No code changes. Signed-off-by: Royyan Zahir <[email protected]>
uaccess_ok() says whether a range lies in the caller's address environment and uaccess_check() kills the caller when it does not. They are how a kernel build refuses a kernel address passed in by a process. Signed-off-by: Royyan Zahir <[email protected]>
access_ok() trusts the user address range, so a kernel mapping inside it would pass as user memory. Refuse such a mapping: at boot the kernel stops, arm64_mmu_set_memregion() returns -EINVAL. Signed-off-by: Royyan Zahir <[email protected]>
access_ok() trusts the user address range, so a global kernel leaf inside it would pass as user memory. Refuse such a mapping. Signed-off-by: Royyan Zahir <[email protected]>
arch.h declares it for an address environment; x86_64 had the same check as the private x86_64_uservaddr(), which it replaces. The syscall checks need it in every kernel build. Signed-off-by: Royyan Zahir <[email protected]>
risc-v and x86_64 walk the active page tables for up_addrenv_va_to_pa() the way arm64 does. drivers/misc/addrenv.c defined the same symbol from a static table, which cannot see user mappings: in a kernel build it now steps aside and arm64 builds its walker there too. Outside a kernel build nothing changes. Signed-off-by: Royyan Zahir <[email protected]>
Make.defs already compiles riscv_addrenv_pgmap.c, but CMake omitted it. Kernel builds that call up_addrenv_va_to_pa() then fail to link. Add the source to the CMake list so both build systems include the walker. Signed-off-by: Royyan Zahir <[email protected]>
Wrap the new riscv_addrenv_pgmap.c entry as cmake-format requires. This fixes the Check workflow for the CMake source change. Signed-off-by: Royyan Zahir <[email protected]>
|
ci break fixed by apache/nuttx-apps#3914 |
Note: Please adhere to Contributing Guidelines.
Summary
In a kernel build a syscall trusts every pointer a process passes. A process can hand the kernel a kernel address and have it read out, written to, or followed through a nested pointer. This PR adds what the checks stand on. The checks at the syscall boundary follow in their own PR once this lands, so where they belong, the generated stubs or the functions, can be settled there.
sched/addrenvuaccess_ok()anduaccess_check(); the latter ends the caller with exit status 11 throughuaccess_fault()-EINVALup_addrenv_user_vaddr(), whicharch.halready declares; replaces the privatex86_64_uservaddr()archup_addrenv_va_to_pa()like arm64; in a kernel build the table indrivers/misc/addrenv.csteps aside, as it cannot see user mappingsMake.defsImpact
uaccess_fault()calls_exit(SIGSEGV). HereSIGSEGVis only the integer exit status 11: the task exits normally with that status. No SIGSEGV is raised or delivered to a signal handler. These helpers check the address window, not whether every page is mapped or accessible. Fault recovery is separate work in #20822.Kernel builds only. Nothing calls the new checks yet. A kernel mapping over the user window is refused, and in risc-v and x86_64 kernel builds the MMU answers
up_addrenv_va_to_pa(), also withDEV_SIMPLE_ADDRENV. Flat and protected builds unchanged.Testing
Rebased on upstream
42a4ba59c4atee1d78fb9c.tools/checkpatch.sh -g upstream/master..HEADpassed. Fresh CMake builds ofrv-virt:knsh64andqemu-intel64:knsh_romfspassed.GitHub Check and Lint passed. The Build run failed in
Linux (risc-v-06)atrv-virt:pnsh: nuttx-appssystem/nxinit/init.cstill callsBOARDIOC_BUILTINS, which NuttX removed in #20964. This is the current cross-repo pairing issue, also reproduced and addressed by apache/nuttx-apps#3914. The Linux matrix cancelled ten other jobs after that failure: https://github.com/apache/nuttx/actions/runs/40192868529. Neithersystem/nxinitnorBOARDIOC_BUILTINSis changed in this PR.Earlier CI on
8e5bbca2ddpassed the Linux architecture jobs, MSVC, and the out-of-tree build; that run was cancelled when MSYS2 was cancelled: https://github.com/apache/nuttx/actions/runs/36981867793.Independent runtime validation by @casaroli on a rebase to
c7cba680a10:qemu-armv8a:knshand:nshOSTest exited 0. Review: #20412 (review).Targeted page-table walker probe on
ee1d78fb9c: a temporary user program passes a global and a stack address throughBOARDIOC_USER. The temporary kernel handler checks the translated physical byte is0x5a, the next virtual byte maps to the next physical byte, kernel text maps, and NULL does not map. On x86_64 it also checks that the last user-window address is accepted and the next address is rejected. The probe code is not part of this PR.rv-virt:knsh64qemu-intel64:knsh_romfsThe x86_64 result exercises the walker with that test-only CPU config; a stock-config runtime run still needs KVM. The upstream ELF loader now accepts
R_X86_64_NONE, so this run needed no loader workaround. The RISC-V result runs without architecture or loader workarounds.Both fresh configs built cleanly on
ee1d78fb9cbefore the temporary probes were applied. The probe sources have been removed from the worktree.Rebased builds and runs: Ubuntu 26.04.1, x86_64, in
ghcr.io/apache/nuttx/apache-nuttx-ci-linux(QEMU 6.2, xPack RISC-V GCC 14.3). The earlier Arm runs below used Ubuntu 24.04 and Arm GNU GCC 13.2.Earlier QEMU runs before this rebase:
helloostestqemu-armv8a:knshExiting with status 0rv-virt:knsh64Started user_main at PID=6, as master doesqemu-intel64:knsh_romfsnx_bringup.c:370in QEMU too, so not comparedAlso built:
canmv230:remote,canmv230:master,qemu-intel64:knsh_romfs_pci,rv-virt:knetnsh64,qemu-armv8a:fb,qemu-armv7a:full,sim:nsh.qemu-armv8a:knsh:hello, thenostestrv-virt:knsh64:hello, thenostest; identical to master'stools/checkpatch.sh -c -u -m -gclean.