Repository navigation
Conversation
linguini1
left a comment
There was a problem hiding this comment.
Provided test logs do not match OS Test output.
Please read the contribution guide, this is another large PR that has been opened without following the contributing guidelines, including testing or being split into logical, smaller patches.
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; uaccess_check() kills the caller when it does not, and uaccess_nested() checks a pointer found inside a user structure. They are how a kernel build refuses a kernel address passed in by a process. Signed-off-by: Royyan Zahir <[email protected]>
uaccess_ok() trusts the user address range, so a kernel mapping inside it would pass as user memory. Refuse such a mapping at boot. Signed-off-by: Royyan Zahir <[email protected]>
uaccess_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 did not have it. 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]>
Every pointer argument must be user memory. Nested pointers are copied in first, ioctl, fcntl and boardctl arguments the kernel alone can reach fail with EFAULT, and user syslog is formatted in the caller. Signed-off-by: Royyan Zahir <[email protected]>
DIOC_GETPRIV and BIOC_XIPBASE handed kernel addresses to the caller, and CAIOC_REGISTERCB stored a user function the kernel later called. Signed-off-by: Royyan Zahir <[email protected]>
SIOCGIFCONF and SIOCGLIFCONF wrote interface records through a buffer pointer and length taken from the caller, as did MMC_IOC_CMD through data_ptr; I2CIOC_TRANSFER and SPIIOC_TRANSFER passed message arrays whose buffers the driver followed. A process could aim any of them at kernel memory. Each struct and array is copied in, every buffer checked as user memory for its full length, and the kernel copy passed down. Signed-off-by: Royyan Zahir <[email protected]>
|
Replaced with the full QEMU |
Sorry. I meant to open this as a draft until all the logs were in; collecting them took longer than expected. Aware of the guidelines. Full QEMU ostest output and the device log are now in the description. |
|
Thanks! Please follow the PR template though. |
|
Done: template applied here and on the related PRs. |
|
This is many commits, could it be split into smaller patches? Also, please add "Assisted-by" to your commit messages as in contribution guide. |
|
Only the last commit is this PR, the other 8 are #20412 which it depends on. Moving it to draft until that lands, then it's one commit. |
|
I would suggest waiting to open PRs or just opening them with the single relevant commit until the dependent ones are merged. They all use our limited CI resources on each push otherwise |
casaroli
left a comment
There was a problem hiding this comment.
The nested copy-in for ifconf, mmc, i2c and spi is careful, and the size and count bounds look right.
The open point is still where the checks live. xiaoxiang asked to keep the syscall-specific handling out of the general stub/proxy creator in tools/mksyscall.c, and that part is unchanged here. Could we settle it first, the way #20425 put its checks into the functions?
Two notes from reading:
- The generated per-pointer check is
uaccess_check(parm, 1): one byte. It does not bound the whole object, so a pointer that starts in the user window but runs past its end still passes the generic stub. Only the hand-written wrappers check the full length. Worth saying in the body. BIOC_XIPBASEandDIOC_GETPRIVnow returnEPERMto user space in a kernel build. That is a behaviour change for XIP users; please call it out.
Test: I rebased on master (c7cba68) and ran qemu-armv8a:knsh and :nsh; ostest exits 0 on both. With a kernel-pointer test, master panics the whole kernel on read(fd, (void *)0x1000, 1) (EL1 translation fault, arm64_fatal.c:696). With this PR the kernel logs 0x1000 is not user memory, the caller ends and NSH keeps running.
One gap stays: an address inside the user window that is not mapped (read(fd, (void *)0xF0000000, 1)) still panics the kernel, because the window check accepts it. That is wider than this PR; I wrote it up in #1329 together with the other cross-PR points.
Note: Please adhere to Contributing Guidelines.
Summary
Depends on #20412; its commits are included until it merges.
The syscall gate checks the ioctl argument itself. Some ioctls carry a structure that holds further user pointers, which the driver then reads or writes with the kernel's rights. In a kernel build a process could point one of them at kernel memory.
uaccess_ioctlcopies the outer structure into the kernel, checks each nested pointer and its length, and hands the driver the copy.SIOCGIFCONF,SIOCGLIFCONFifc_bufforifc_lenMMC_IOC_CMD,MMC_IOC_MULTI_CMDdata_ptrforblksz * blocks, at least 512; at mostMMC_IOC_MAX_CMDSI2CIOC_TRANSFERSPIIOC_TRANSFERnwordswords of 1, 2 or 4 bytesImpact
Kernel builds with network, MMC, I2C or SPI drivers. A nested pointer into kernel memory returns
EFAULT. Flat and protected builds unchanged.Testing
Host: Ubuntu 24.04, x86_64. Builds and QEMU runs in
ghcr.io/apache/nuttx/apache-nuttx-ci-linux(QEMU 6.2, Arm GNU GCC 13.2, xPack RISC-V GCC 14.3). Hardware: i.MX93 (Cortex-A55), PX4 kernel build.qemu-armv8a:knshostestpasses;hellorv-virt:knsh64hello;osteststops afterStarted user_main at PID=6, as master doesqemu-armv8a:knsh+ NET, MMCSD, I2C_DRIVER, SPI_DRIVERerrno 25 is the driver's own
ENOTTY: that board hasMMCSD_IOCSUPPORToff, so the call reached it.qemu-armv8a:knsh:hello, thenostestrv-virt:knsh64:hello, thenostest; identical to master'si.MX93, PX4 kernel build, this series applied:
tests isolationtools/checkpatch.sh -c -u -m -gclean.