mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 06:18:59 +00:00
Kernel+LibC: Allow passing mount flags to chroot()
Since a chroot is in many ways similar to a separate root mount, we can also apply mount flags to it as if it was an actual mount. These flags will apply whenever the chrooted process accesses its root directory, but not when other processes access this same directory for the outside. Since it's common to chdir("/") immediately after chrooting (so that files accessed through the current directory inherit the same mount flags), this effectively allows one to apply additional limitations to a process confined inside a chroot. To this effect, sys$chroot() gains a mount_flags argument (exposed as chroot_with_mount_flags() in userspace) which can be set to all the same values as the flags argument for sys$mount(), and additionally to -1 to keep the flags set for that file system. Note that passing 0 as mount_flags will unset any flags that may have been set for the file system, not keep them.
This commit is contained in:
parent
fee6d0a3a6
commit
dd54d13d8d
Notes:
sideshowbarker
2024-07-19 10:07:05 +09:00
Author: https://github.com/bugaevc
Commit: dd54d13d8d
Pull-request: https://github.com/SerenityOS/serenity/pull/1063
4 changed files with 11 additions and 4 deletions
|
@ -4337,8 +4337,9 @@ int Process::sys$chroot(const char* user_path, size_t path_length)
|
|||
if (directory_or_error.is_error())
|
||||
return directory_or_error.error();
|
||||
auto directory = directory_or_error.value();
|
||||
m_root_directory_for_procfs = directory;
|
||||
set_root_directory(Custody::create(nullptr, "", directory->inode(), directory->mount_flags()));
|
||||
m_root_directory_relative_to_global_root = directory;
|
||||
int chroot_mount_flags = mount_flags == -1 ? directory->mount_flags() : mount_flags;
|
||||
set_root_directory(Custody::create(nullptr, "", directory->inode(), chroot_mount_flags));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue