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. |
3f75a6c to
0647bd2
Compare
0647bd2 to
330134a
Compare
330134a to
8a93d1f
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>
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>
8a93d1f to
62982eb
Compare
| if (ret < 0) | ||
| { | ||
| ferr("ERROR: Failed to find %s\n", pathname); | ||
| ret = -ENOENT; |
| if (ret < 0) | ||
| { | ||
| ferr("ERROR: Failed to find %s\n", pathname); | ||
| ret = -ENOENT; |
| inode_rlock(); | ||
| ret = inode_search(desc); | ||
| ret = inode_search(desc, inode); | ||
| if (ret >= 0) |
There was a problem hiding this comment.
need check inode isnot NULL
| ret = inode_search_setup(&desc, path2, false); | ||
| if (ret < 0) | ||
| { | ||
| errcode = -ret; |
There was a problem hiding this comment.
remove errcode too
| ret = desc.node->u.i_mops->symlink(desc.node, path1, | ||
| desc.relpath); | ||
| ret = inode->u.i_mops->symlink(inode, path1, | ||
| desc.relpath); |
| } | ||
|
|
||
| ret = inode_search(&olddesc, &oldfound); | ||
| inode_search_release(&olddesc); |
| @@ -155,7 +157,8 @@ static int _inode_compare(FAR const char *fname, FAR struct inode *inode) | |||
|
|
|||
| #ifdef CONFIG_FS_LINKS | |||
| static int _inode_linktarget(FAR struct inode *inode, | |||
There was a problem hiding this comment.
let change inode to ** directly
| ****************************************************************************/ | ||
|
|
||
| int inode_search(FAR struct inode_search_s *desc) | ||
| int inode_search_setup(FAR struct inode_search_s *desc, |
There was a problem hiding this comment.
Move before inode_search to reduce the difference
|
|
||
| if (inodep != NULL) | ||
| { | ||
| *inodep = inode; |
There was a problem hiding this comment.
why update in the fail path
| * | ||
| ****************************************************************************/ | ||
|
|
||
| void inode_search_release(FAR struct inode_search_s *desc) |
There was a problem hiding this comment.
Move before inode_search_setup
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):