fs,sched: add chroot() filesystem jail - #19900
Conversation
|
Nice work @Abhishekmishra2808 ! |
|
5b250cc to
d3ea539
Compare
|
@acassis PTAL ! |
1dbd097 to
82821d6
Compare
|
ci was fixed, please rebase your change to the last master. @Abhishekmishra2808, many code can be simplified with #19991. |
82821d6 to
3f75a6c
Compare
|
@xiaoxiang781216 done |
@Abhishekmishra2808 please fix the conflict. |
0647bd2 to
330134a
Compare
8a93d1f to
62982eb
Compare
62982eb to
83df4a9
Compare
83df4a9 to
c3d257b
Compare
| fs_truncate.c | ||
| fs_link.c) | ||
|
|
||
| if(CONFIG_FS_CHROOT) |
There was a problem hiding this comment.
move this patch after fs: start absolute lookups at the jail root
| @@ -440,7 +446,7 @@ static int automount_findinode(FAR const char *path) | |||
| /* Relinquish our exclusive access to the inode try and return the result */ | |||
|
|
|||
| inode_runlock(); | |||
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>
Prepare paths in inode_search_setup(): prepend tg_root, canonicalize with a jail-floor dst_min, then walk from g_root_inode. Replace SETUP_SEARCH / RELEASE_SEARCH with inode_search_setup() / inode_search_release(). 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>
c3d257b to
4323e0c
Compare
|
@xiaoxiang781216, PTAL |
| #include <nuttx/fs/fs.h> | ||
| #include <nuttx/fs/ioctl.h> | ||
| #include <nuttx/kmalloc.h> | ||
| #include <nuttx/lib/lib.h> |
There was a problem hiding this comment.
revert change in this file
| #include <assert.h> | ||
| #include <stdio.h> | ||
|
|
||
| #include <nuttx/lib/lib.h> |
| fs_link.c) | ||
|
|
||
| if(CONFIG_FS_CHROOT) | ||
| list(APPEND SRCS fs_chroot.c) |
There was a problem hiding this comment.
move to chroot patch
|
|
||
| #include <nuttx/cancelpt.h> | ||
| #include <nuttx/fs/fs.h> | ||
| #include <nuttx/lib/lib.h> |
| CSRCS += fs_syncfs.c fs_truncate.c fs_link.c | ||
|
|
||
| ifeq ($(CONFIG_FS_CHROOT),y) | ||
| CSRCS += fs_chroot.c |
There was a problem hiding this comment.
move to chroot patch
| inode_search_release(&olddesc); | ||
| if (ret >= 0) | ||
| { | ||
| inode_addref(oldfound); |
| */ | ||
|
|
||
| inode_release(newinode); | ||
| newinode = NULL; |
|
|
||
| /* Re-resolve the source under the same lock before unlinking it. */ | ||
|
|
||
| SETUP_SEARCH(&olddesc, oldpath, true); |
There was a problem hiding this comment.
why need re-resolve? let's remove it
| switch (ret) | ||
| { | ||
| case OK_EXIST: | ||
| case OK_EXIST: |
There was a problem hiding this comment.
move the format to new patch
| } | ||
| else | ||
| { | ||
| inode_addref(inode); |
| #include "tls/tls.h" | ||
|
|
||
| #ifdef CONFIG_FS_CHROOT | ||
| # include "../../fs/fs_heap.h" |
There was a problem hiding this comment.
should we continue use kmm_malloc/free instead?
Summary
CONFIG_FS_CHROOTadds POSIXchroot()so a task group can pin a directory as its filesystem root. The jail is stored astg_root(an absolute host path, orNULLif none). Children inherit a copy viastrdup; leaving the group frees it.Lookups stay inside the jail in
inode_search_setup(): join$PWDfor relative paths, prependtg_root, then canonicalize with a jail-floordst_minso..cannot climb out.chroot()does not rewritePWD.chroot("/")from the host root clears the jail; from inside a jail,/is still the jail, so it cannot be used to escape.This is a filesystem jail, not a container: descriptors opened before
chroot()that already point outside the tree remain usable, and the new root is not populated with/devor/proc.Impact
The option is off by default. When enabled,
chroot()is a new syscall and, withSCHED_USER_IDENTITY, requires effective UID 0. Companion apps change: apache/nuttx-apps#3735 (merged).Testing
Host: WSL2 x86_64. Board:
sim(CONFIG_FS_CHROOT=y). Companion apps: apache/nuttx-apps#3735.NSH jail session (syscall from userspace;
chrootbuiltin from apache/nuttx-apps#3735):