diff options
-rw-r--r-- | Kernel/Process.cpp | 5 | ||||
-rw-r--r-- | Kernel/Process.h | 2 | ||||
-rw-r--r-- | Libraries/LibC/unistd.cpp | 7 | ||||
-rw-r--r-- | Libraries/LibC/unistd.h | 1 |
4 files changed, 11 insertions, 4 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 6e1d34dce8..8f5800728c 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -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; } diff --git a/Kernel/Process.h b/Kernel/Process.h index 5eb0c61b27..5921e30703 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -254,7 +254,7 @@ public: int sys$futex(const Syscall::SC_futex_params*); int sys$set_thread_boost(int tid, int amount); int sys$set_process_boost(pid_t, int amount); - int sys$chroot(const char* path, size_t path_length); + int sys$chroot(const char* path, size_t path_length, int mount_flags); int sys$pledge(const Syscall::SC_pledge_params*); static void initialize(); diff --git a/Libraries/LibC/unistd.cpp b/Libraries/LibC/unistd.cpp index 971606b2f8..1d907fda54 100644 --- a/Libraries/LibC/unistd.cpp +++ b/Libraries/LibC/unistd.cpp @@ -645,11 +645,16 @@ int get_process_name(char* buffer, int buffer_size) int chroot(const char* path) { + return chroot_with_mount_flags(path, -1); +} + +int chroot_with_mount_flags(const char* path, int mount_flags) +{ if (!path) { errno = EFAULT; return -1; } - int rc = syscall(SC_chroot, path, strlen(path)); + int rc = syscall(SC_chroot, path, strlen(path), mount_flags); __RETURN_WITH_ERRNO(rc, rc, -1); } diff --git a/Libraries/LibC/unistd.h b/Libraries/LibC/unistd.h index 1ca0095a94..6f6e4b7f42 100644 --- a/Libraries/LibC/unistd.h +++ b/Libraries/LibC/unistd.h @@ -52,6 +52,7 @@ int execvp(const char* filename, char* const argv[]); int execl(const char* filename, const char* arg, ...); int execlp(const char* filename, const char* arg, ...); int chroot(const char* path); +int chroot_with_mount_flags(const char* path, int mount_flags); void sync(); void _exit(int status); pid_t getsid(pid_t); |