fs,sched: add chroot() filesystem jail - #19900
Open
Abhishekmishra2808 wants to merge 4 commits into
Open
Conversation
Abhishekmishra2808
requested review from
Donny9,
anchao,
btashton,
jerpelea,
masayuki2009,
pkarashchenko,
pussuw,
raiden00pl and
xiaoxiang781216
as code owners
August 19, 2026 08:27
acassis
reviewed
Aug 19, 2026
Contributor
|
Nice work @Abhishekmishra2808 ! |
|
Abhishekmishra2808
force-pushed
the
feature/fs-chroot
branch
from
August 23, 2026 07:15
f3fbd17 to
5b250cc
Compare
Store the jail as an absolute path on the task group, copy it to children, and free it when the last member leaves. Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
Add CONFIG_FS_CHROOT and POSIX chroot(). Store the jail as an absolute path on the task group, and require euid 0 when user identity is enabled. Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
Prepend tg_root to absolute paths, normalize, and keep the result under the jail, then walk from g_root_inode. Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
Describe the jail, leftover pre-opened fds, the NSH command-form scrub, and the flat-build trust boundary shared with credentials. Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
Abhishekmishra2808
force-pushed
the
feature/fs-chroot
branch
from
August 24, 2026 03:39
5b250cc to
d3ea539
Compare
Contributor
Author
|
@acassis PTAL ! |
acassis
approved these changes
Aug 24, 2026
Contributor
|
|
||
| /* chroot("/") from the global root is a no-op (tg_root stays NULL). */ | ||
|
|
||
| if (strcmp(abspath, "/") == 0) |
Contributor
There was a problem hiding this comment.
but caller may change to no root before
| return ERROR; | ||
| } | ||
|
|
||
| SETUP_SEARCH(&desc, path, false); |
| out[len] = '\0'; | ||
| } | ||
|
|
||
| strlcat(out, relpath, outlen); |
Contributor
There was a problem hiding this comment.
strlcpy by len offset
| in++; | ||
| } | ||
|
|
||
| seglen = (size_t)(in - seg); |
| } | ||
| else | ||
| { | ||
| size_t used = (size_t)(dst - out); |
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
CONFIG_FS_CHROOTadds POSIXchroot()so a task group can pin a directory as its filesystem root. Absolute lookups start at that inode, children inherit the jail, andPWDis rewritten so relative paths cannot walk out. This is a filesystem jail, not a container: descriptors opened beforechroot()that already point outside the tree remain usable.Impact
The option is off by default. When enabled,
chroot()is a new syscall and, withSCHED_USER_IDENTITY, requires effective UID 0. OnCONFIG_BUILD_FLATtheeuid == 0gate andtg_rootshare the same trust boundary as credentials. Companion apps change: apache/nuttx-apps#3735.Testing
Host: WSL2 x86_64. Board:
sim(CONFIG_FS_CHROOT=y). Companion apps PR: apache/nuttx-apps#3735.NSH no-command form (syscall from userspace;
chrootbuiltin is in apache/nuttx-apps#3735):ostest (kernel jail, leftover fd, inheritance):