From bedd90b1f07e2da8326f2e520c985431fda73a25 Mon Sep 17 00:00:00 2001 From: Liav A Date: Sun, 25 Dec 2022 12:11:27 +0200 Subject: [PATCH] Kernel: Properly lock Process protected data in the prctl syscall --- Kernel/Process.cpp | 7 ------- Kernel/Process.h | 1 - Kernel/Syscalls/prctl.cpp | 20 ++++++++++++-------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 923028fe4f..449772a36d 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -1017,13 +1017,6 @@ bool Process::add_thread(Thread& thread) return is_first; } -void Process::set_dumpable(bool dumpable) -{ - with_mutable_protected_data([&](auto& protected_data) { - protected_data.dumpable = dumpable; - }); -} - ErrorOr Process::set_coredump_property(NonnullOwnPtr key, NonnullOwnPtr value) { return m_coredump_properties.with([&](auto& coredump_properties) -> ErrorOr { diff --git a/Kernel/Process.h b/Kernel/Process.h index bdcec8602b..7950df8b9c 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -249,7 +249,6 @@ public: { return with_protected_data([](auto& protected_data) { return protected_data.dumpable; }); } - void set_dumpable(bool); mode_t umask() const { diff --git a/Kernel/Syscalls/prctl.cpp b/Kernel/Syscalls/prctl.cpp index f7f26c8de5..4838a758da 100644 --- a/Kernel/Syscalls/prctl.cpp +++ b/Kernel/Syscalls/prctl.cpp @@ -12,14 +12,18 @@ namespace Kernel { ErrorOr Process::sys$prctl(int option, FlatPtr arg1, [[maybe_unused]] FlatPtr arg2) { VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); - switch (option) { - case PR_GET_DUMPABLE: - return is_dumpable(); - case PR_SET_DUMPABLE: - set_dumpable(arg1); - return 0; - } - return EINVAL; + return with_mutable_protected_data([&](auto& protected_data) -> ErrorOr { + switch (option) { + case PR_GET_DUMPABLE: + return protected_data.dumpable; + case PR_SET_DUMPABLE: + if (arg1 != 0 && arg1 != 1) + return EINVAL; + protected_data.dumpable = arg1; + return 0; + } + return EINVAL; + }); } }