fs,sched: add chroot() filesystem jail - #19900
Conversation
chroot() holds a directory inode in the task group, so sched needs the existing refcount helpers instead of duplicating them. Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
Store tg_root / tg_rootrel on the task group, copy them to children, and drop the inode when the last member leaves. Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
Add CONFIG_FS_CHROOT and POSIX chroot(). Pin a directory as the group root, rewrite PWD, and require euid 0 when user identity is enabled. Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
Walk from tg_root instead of the global pseudo-root, clamp ".." at the
jail, and normalize absolute paths so chroot(".") under a mount does
not pass a leftover "." as relpath.
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>
| nsh> pwd | ||
| / |
There was a problem hiding this comment.
@Abhishekmishra2808 add here after pwd the "nsh> ls /" to show that there is not /dev, /proc available.
| This is **not** a container. NuttX does not provide PID, mount, or | ||
| network namespaces. ``chroot()`` only changes where pathname lookup | ||
| begins. |
There was a problem hiding this comment.
Maybe instead of saying "NuttX does not provide PID, mount, or network namespaces" that some people will take as true (and of course NuttX has it), I suggest adding:
Limitations: currently chroot doesn't support PID, mount, network namespaces and explain the next start as a TODO. What need to be done to support it
There was a problem hiding this comment.
Correct !
| .. _chroot: | ||
|
|
||
| ====== | ||
| chroot |
There was a problem hiding this comment.
I think this "implementation" is misleading: you didn't explain how it was implemented, what was necessary, why did you spend an week implementing it to explain what was the difficult part of the implementation
There was a problem hiding this comment.
I saw other examples. Agreed on this point !!
| ============ | ||
|
|
||
| Bind-mounts or unionfs to populate ``/dev`` inside a jail, mount/PID/ | ||
| network namespaces, and ``pivot_root()`` are not provided. |
There was a problem hiding this comment.
Please explain the challenges here, why wasn't it implemented?
| Flat Build Trust Boundary | ||
| ========================= | ||
|
|
||
| This credential model is a DAC layer for cooperating tasks, not a |
There was a problem hiding this comment.
What is DAC? Digital Analog Converter? Please explain what is DAC in this context
| * (tmpfs /tmp) the leftover "." is passed to the filesystem as | ||
| * relpath and fails with ENOENT. | ||
| * | ||
| ****************************************************************************/ |
There was a problem hiding this comment.
Please include the Input parameters and the return
|
Nice work @Abhishekmishra2808 ! |
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):