Repository navigation
Conversation
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]>
The kernel ran the process's heap allocator on the process's own metadata to set or clear a variable, and freed the environment from whatever address space was current at exit. libc now owns it and tells the kernel where it is; the kernel only reads it, pointer by pointer. Signed-off-by: Royyan Zahir <[email protected]>
royzah
requested review from
Donny9,
anchao,
jerpelea,
linguini1,
lupyuen,
masayuki2009,
pkarashchenko,
pussuw,
xiaoxiang781216 and
yf13
as code owners
October 1, 2026 01:17
|
| #ifndef CONFIG_DISABLE_ENVIRON | ||
| SYSCALL_LOOKUP(get_environ_ptr, 0) | ||
| # ifdef CONFIG_BUILD_KERNEL | ||
| SYSCALL_LOOKUP(set_environ_ptr, 1) |
Contributor
There was a problem hiding this comment.
but the correct fix is moved all environ stuff to userapce, we have a patch series do this, will create a new pr soon.
Contributor
Author
There was a problem hiding this comment.
Nice, thats the better fix. Will close this once yours is up, happy to test it on our imx93 kernel build.
|
|
||
| FAR char **get_environ_ptr(void); | ||
| #ifdef CONFIG_BUILD_KERNEL | ||
| void set_environ_ptr(FAR char **envp); |
Contributor
There was a problem hiding this comment.
please drop the first eight patch
royzah
marked this pull request as draft
October 1, 2026 10:57
Contributor
Author
|
Closing this in favor of #20583, now merged. It moves the environment functions into libc and keeps the environment in task_info, covering the approach discussed here. Thanks for carrying it forward. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: Please adhere to Contributing Guidelines.
Summary
Depends on #20412; its commits are included until it merges. Split out of #20416.
In a kernel build the kernel ran a process's own heap allocator, on metadata the process controls, to set or clear an environment variable. At exit it freed the environment from whatever address space happened to be current.
libc owns the environment in a kernel build and tells the kernel where it is with
set_environ_ptr(); the kernel only reads it, pointer by pointer, when it spawns.getenv,setenv,putenv,unsetenvandclearenvleave the syscall table there.env_sanitize_secure()on master still edits the environment in the kernel. Nothing calls it today; in a kernel build it would need to go through the process.Impact
Kernel builds: libc owns the environment;
getenv,setenv,putenv,unsetenv,clearenvleave the syscall table. 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, its environment checks included;hellorv-virt:knsh64hello;osteststops afterStarted user_main at PID=6, as master doesqemu-armv8a:knsh:hello, thenostestrv-virt:knsh64:hello, thenostest; identical to master'stools/checkpatch.sh -c -u -m -gclean.