nshlib,testing: add chroot command and ostest - #3735
Open
Abhishekmishra2808 wants to merge 3 commits into
Open
Conversation
chdir into the new root, call chroot("."), then chdir("/") so relative
paths stay in the jail. With a command, execvp() after the jail is set.
Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
chroot <newroot> <command> closes non-stdio, non-O_CLOEXEC descriptors before execvp so inherited host fds cannot bypass the jail. Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
Check jail visibility, host-path isolation, child inheritance, and that a pre-opened host fd remains usable after chroot(). Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
jerpelea
approved these changes
Aug 19, 2026
acassis
approved these changes
Aug 20, 2026
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.
Summary
Adds an NSH
chroothelper thatchdirs into the new root, callschroot("."), thenchdir("/")so relative paths stay in the jail. The command formchroot <newroot> <command>closes non-stdio, non-O_CLOEXECdescriptors beforeexecvpso inherited host fds cannot bypass the jail. ostest covers jail visibility, host-path isolation, child inheritance, and leftover pre-opened fds.Impact
The NSH command is gated by
CONFIG_FS_CHROOTand can be disabled withCONFIG_NSH_DISABLE_CHROOT. ostest runs the new case only whenCONFIG_FS_CHROOTandCONFIG_SCHED_WAITPIDare set and the build is not kernel. Companion kernel change is apache/nuttx#19900.Testing
Host: WSL2 x86_64. Board:
sim(CONFIG_FS_CHROOT=y,CONFIG_TESTING_OSTEST=y), with nuttxfeature/fs-chroot.