mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:17:35 +00:00
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.
This commit is contained in:
parent
96d5d017b7
commit
1b739a72c2
19 changed files with 3 additions and 289 deletions
|
@ -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) \
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -31,7 +31,6 @@ enum class MainProcessProperty {
|
|||
CurrentWorkDirectoryLink = 5,
|
||||
PerformanceEvents = 6,
|
||||
VirtualMemoryStats = 7,
|
||||
RootLink = 8,
|
||||
};
|
||||
|
||||
enum class ProcessSubDirectory {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue