diff options
author | Andreas Kling <kling@serenityos.org> | 2021-08-15 01:29:44 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-15 12:44:35 +0200 |
commit | 1b739a72c23954092fbecaba5816458ce3276deb (patch) | |
tree | 6598a8a583c1c4d4badec18dd9da606c88a7d41d /Kernel | |
parent | 96d5d017b70e26605d2340f5a27707db4302b4df (diff) | |
download | serenity-1b739a72c23954092fbecaba5816458ce3276deb.zip |
Kernel+Userland: Remove chroot functionality
We are not using this for anything and it's just been sitting there
gathering dust for well over a year, so let's stop carrying all this
complexity around for no good reason.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/API/Syscall.h | 1 | ||||
-rw-r--r-- | Kernel/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Kernel/FileSystem/ProcFS.cpp | 10 | ||||
-rw-r--r-- | Kernel/FileSystem/VirtualFileSystem.cpp | 3 | ||||
-rw-r--r-- | Kernel/Process.cpp | 21 | ||||
-rw-r--r-- | Kernel/Process.h | 9 | ||||
-rw-r--r-- | Kernel/ProcessExposed.h | 1 | ||||
-rw-r--r-- | Kernel/ProcessProcFSTraits.cpp | 1 | ||||
-rw-r--r-- | Kernel/ProcessSpecificExposed.cpp | 6 | ||||
-rw-r--r-- | Kernel/Syscalls/chroot.cpp | 38 | ||||
-rw-r--r-- | Kernel/Syscalls/fork.cpp | 2 | ||||
-rw-r--r-- | Kernel/Syscalls/unveil.cpp | 2 | ||||
-rw-r--r-- | Kernel/init.cpp | 2 |
13 files changed, 2 insertions, 95 deletions
diff --git a/Kernel/API/Syscall.h b/Kernel/API/Syscall.h index de49c627b8..d2c9f33926 100644 --- a/Kernel/API/Syscall.h +++ b/Kernel/API/Syscall.h @@ -55,7 +55,6 @@ enum class NeedsBigProcessLock { S(chdir, NeedsBigProcessLock::Yes) \ S(chmod, NeedsBigProcessLock::Yes) \ S(chown, NeedsBigProcessLock::Yes) \ - S(chroot, NeedsBigProcessLock::Yes) \ S(clock_gettime, NeedsBigProcessLock::No) \ S(clock_nanosleep, NeedsBigProcessLock::No) \ S(clock_settime, NeedsBigProcessLock::Yes) \ diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 46527b4e79..55374465a3 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -195,7 +195,6 @@ set(KERNEL_SOURCES Syscalls/chdir.cpp Syscalls/chmod.cpp Syscalls/chown.cpp - Syscalls/chroot.cpp Syscalls/clock.cpp Syscalls/debug.cpp Syscalls/disown.cpp diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index cb3b587612..5af24f0f6a 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -360,12 +360,6 @@ KResultOr<NonnullRefPtr<Inode>> ProcFSProcessDirectoryInode::lookup(StringView n return maybe_inode.error(); return maybe_inode.release_value(); } - if (name == "root") { - auto maybe_inode = ProcFSProcessPropertyInode::try_create_for_pid_property(procfs(), SegmentedProcFSIndex::MainProcessProperty::RootLink, associated_pid()); - if (maybe_inode.is_error()) - return maybe_inode.error(); - return maybe_inode.release_value(); - } return ENOENT; } @@ -515,8 +509,6 @@ static mode_t determine_procfs_process_inode_mode(SegmentedProcFSIndex::ProcessS return S_IFLNK | 0777; if (main_property == SegmentedProcFSIndex::MainProcessProperty::CurrentWorkDirectoryLink) return S_IFLNK | 0777; - if (main_property == SegmentedProcFSIndex::MainProcessProperty::RootLink) - return S_IFLNK | 0777; return S_IFREG | 0400; } @@ -625,8 +617,6 @@ KResult ProcFSProcessPropertyInode::try_to_acquire_data(Process& process, KBuffe return process.procfs_get_perf_events(builder); case SegmentedProcFSIndex::MainProcessProperty::VirtualMemoryStats: return process.procfs_get_virtual_memory_stats(builder); - case SegmentedProcFSIndex::MainProcessProperty::RootLink: - return process.procfs_get_root_link(builder); default: VERIFY_NOT_REACHED(); } diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 81fb54a9d8..3cb67996e4 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -934,9 +934,8 @@ KResultOr<NonnullRefPtr<Custody>> VirtualFileSystem::resolve_path_without_veil(S GenericLexer path_lexer(path); auto current_process = Process::current(); - auto& current_root = current_process->root_directory(); - NonnullRefPtr<Custody> custody = path[0] == '/' ? current_root : base; + NonnullRefPtr<Custody> custody = path[0] == '/' ? root_custody() : base; bool extra_iteration = path[path.length() - 1] == '/'; while (!path_lexer.is_eof() || extra_iteration) { diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 9b1a05b078..a3ad914a69 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -609,8 +609,6 @@ void Process::finalize() m_tty = nullptr; m_executable = nullptr; m_cwd = nullptr; - m_root_directory = nullptr; - m_root_directory_relative_to_global_root = nullptr; m_arguments.clear(); m_environment.clear(); @@ -775,25 +773,6 @@ void Process::FileDescriptionAndFlags::set(NonnullRefPtr<FileDescription>&& desc m_flags = flags; } -Custody& Process::root_directory() -{ - if (!m_root_directory) - m_root_directory = VirtualFileSystem::the().root_custody(); - return *m_root_directory; -} - -Custody& Process::root_directory_relative_to_global_root() -{ - if (!m_root_directory_relative_to_global_root) - m_root_directory_relative_to_global_root = root_directory(); - return *m_root_directory_relative_to_global_root; -} - -void Process::set_root_directory(const Custody& root) -{ - m_root_directory = root; -} - void Process::set_tty(TTY* tty) { m_tty = tty; diff --git a/Kernel/Process.h b/Kernel/Process.h index 58ecf484e1..b37837fc98 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -57,7 +57,6 @@ Time kgettimeofday(); __ENUMERATE_PLEDGE_PROMISE(fattr) \ __ENUMERATE_PLEDGE_PROMISE(tty) \ __ENUMERATE_PLEDGE_PROMISE(chown) \ - __ENUMERATE_PLEDGE_PROMISE(chroot) \ __ENUMERATE_PLEDGE_PROMISE(thread) \ __ENUMERATE_PLEDGE_PROMISE(video) \ __ENUMERATE_PLEDGE_PROMISE(accept) \ @@ -392,7 +391,6 @@ public: KResultOr<FlatPtr> sys$profiling_disable(pid_t); KResultOr<FlatPtr> sys$profiling_free_buffer(pid_t); KResultOr<FlatPtr> sys$futex(Userspace<const Syscall::SC_futex_params*>); - KResultOr<FlatPtr> sys$chroot(Userspace<const char*> path, size_t path_length, int mount_flags); KResultOr<FlatPtr> sys$pledge(Userspace<const Syscall::SC_pledge_params*>); KResultOr<FlatPtr> sys$unveil(Userspace<const Syscall::SC_unveil_params*>); KResultOr<FlatPtr> sys$perf_event(int type, FlatPtr arg1, FlatPtr arg2); @@ -454,10 +452,6 @@ public: Mutex& big_lock() { return m_big_lock; } Mutex& ptrace_lock() { return m_ptrace_lock; } - Custody& root_directory(); - Custody& root_directory_relative_to_global_root(); - void set_root_directory(const Custody&); - bool has_promises() const { return m_protected_values.has_promises; } bool has_promised(Pledge pledge) const { return m_protected_values.promises & (1u << (u32)pledge); } @@ -559,7 +553,6 @@ public: KResult procfs_get_pledge_stats(KBufferBuilder& builder) const; KResult procfs_get_virtual_memory_stats(KBufferBuilder& builder) const; KResult procfs_get_binary_link(KBufferBuilder& builder) const; - KResult procfs_get_root_link(KBufferBuilder& builder) const; KResult procfs_get_current_work_directory_link(KBufferBuilder& builder) const; mode_t binary_link_required_mode() const; KResultOr<size_t> procfs_get_thread_stack(ThreadID thread_id, KBufferBuilder& builder) const; @@ -760,8 +753,6 @@ private: RefPtr<Custody> m_executable; RefPtr<Custody> m_cwd; - RefPtr<Custody> m_root_directory; - RefPtr<Custody> m_root_directory_relative_to_global_root; Vector<String> m_arguments; Vector<String> m_environment; diff --git a/Kernel/ProcessExposed.h b/Kernel/ProcessExposed.h index 5c8b6aba19..91c18e2ccc 100644 --- a/Kernel/ProcessExposed.h +++ b/Kernel/ProcessExposed.h @@ -31,7 +31,6 @@ enum class MainProcessProperty { CurrentWorkDirectoryLink = 5, PerformanceEvents = 6, VirtualMemoryStats = 7, - RootLink = 8, }; enum class ProcessSubDirectory { diff --git a/Kernel/ProcessProcFSTraits.cpp b/Kernel/ProcessProcFSTraits.cpp index 8e8a018974..e15021329d 100644 --- a/Kernel/ProcessProcFSTraits.cpp +++ b/Kernel/ProcessProcFSTraits.cpp @@ -65,7 +65,6 @@ KResult Process::ProcessProcFSTraits::traverse_as_directory(unsigned fsid, Funct callback({ "cwd", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::CurrentWorkDirectoryLink) }, 0 }); callback({ "perf_events", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::PerformanceEvents) }, 0 }); callback({ "vm", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::VirtualMemoryStats) }, 0 }); - callback({ "root", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::RootLink) }, 0 }); return KSuccess; } diff --git a/Kernel/ProcessSpecificExposed.cpp b/Kernel/ProcessSpecificExposed.cpp index e42a2adbe3..03a53882fe 100644 --- a/Kernel/ProcessSpecificExposed.cpp +++ b/Kernel/ProcessSpecificExposed.cpp @@ -218,12 +218,6 @@ KResult Process::procfs_get_fds_stats(KBufferBuilder& builder) const return KSuccess; } -KResult Process::procfs_get_root_link(KBufferBuilder& builder) const -{ - builder.append_bytes(const_cast<Process&>(*this).root_directory_relative_to_global_root().absolute_path().to_byte_buffer()); - return KSuccess; -} - KResult Process::procfs_get_virtual_memory_stats(KBufferBuilder& builder) const { JsonArraySerializer array { builder }; diff --git a/Kernel/Syscalls/chroot.cpp b/Kernel/Syscalls/chroot.cpp deleted file mode 100644 index 5f13bccc91..0000000000 --- a/Kernel/Syscalls/chroot.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include <AK/StringView.h> -#include <Kernel/FileSystem/Custody.h> -#include <Kernel/FileSystem/VirtualFileSystem.h> -#include <Kernel/Process.h> - -namespace Kernel { - -KResultOr<FlatPtr> Process::sys$chroot(Userspace<const char*> user_path, size_t path_length, int mount_flags) -{ - VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); - if (!is_superuser()) - return EPERM; - REQUIRE_PROMISE(chroot); - auto path = get_syscall_path_argument(user_path, path_length); - if (path.is_error()) - return path.error(); - auto directory_or_error = VirtualFileSystem::the().open_directory(path.value()->view(), current_directory()); - if (directory_or_error.is_error()) - return directory_or_error.error(); - auto directory = directory_or_error.value(); - m_root_directory_relative_to_global_root = directory; - int chroot_mount_flags = mount_flags == -1 ? directory->mount_flags() : mount_flags; - - auto custody_or_error = Custody::try_create(nullptr, "", directory->inode(), chroot_mount_flags); - if (custody_or_error.is_error()) - return custody_or_error.error(); - - set_root_directory(custody_or_error.release_value()); - return 0; -} - -} diff --git a/Kernel/Syscalls/fork.cpp b/Kernel/Syscalls/fork.cpp index cc6bc8d229..6f166e15aa 100644 --- a/Kernel/Syscalls/fork.cpp +++ b/Kernel/Syscalls/fork.cpp @@ -21,8 +21,6 @@ KResultOr<FlatPtr> Process::sys$fork(RegisterState& regs) auto child = Process::create(child_first_thread, m_name, uid(), gid(), pid(), m_is_kernel_process, m_cwd, m_executable, m_tty, this); if (!child || !child_first_thread) return ENOMEM; - child->m_root_directory = m_root_directory; - child->m_root_directory_relative_to_global_root = m_root_directory_relative_to_global_root; child->m_veil_state = m_veil_state; child->m_unveiled_paths = m_unveiled_paths.deep_copy(); diff --git a/Kernel/Syscalls/unveil.cpp b/Kernel/Syscalls/unveil.cpp index 710011a8e4..9ecf2f0e9e 100644 --- a/Kernel/Syscalls/unveil.cpp +++ b/Kernel/Syscalls/unveil.cpp @@ -92,7 +92,7 @@ KResultOr<FlatPtr> Process::sys$unveil(Userspace<const Syscall::SC_unveil_params // If this case is encountered, the parent node of the path is returned and the custody of that inode is used instead. RefPtr<Custody> parent_custody; // Parent inode in case of ENOENT OwnPtr<KString> new_unveiled_path; - auto custody_or_error = VirtualFileSystem::the().resolve_path_without_veil(path.view(), root_directory(), &parent_custody); + auto custody_or_error = VirtualFileSystem::the().resolve_path_without_veil(path.view(), VirtualFileSystem::the().root_custody(), &parent_custody); if (!custody_or_error.is_error()) { new_unveiled_path = custody_or_error.value()->try_create_absolute_path(); if (!new_unveiled_path) diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 65d737c73e..bd275461d6 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -325,8 +325,6 @@ void init_stage2(void*) PANIC("VirtualFileSystem::mount_root failed"); } - Process::current()->set_root_directory(VirtualFileSystem::the().root_custody()); - // Switch out of early boot mode. g_in_early_boot = false; |