diff options
author | Liav A <liavalb@gmail.com> | 2023-03-01 21:28:51 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-03-05 16:55:08 +0100 |
commit | be1d7c325a5e2483038f82d2303a9de3a007be5d (patch) | |
tree | 880cc173491ba86d0162958ecf110f12f0b7e481 | |
parent | 822164a6864d4e43b09607bc787dac1622ebe6fd (diff) | |
download | serenity-be1d7c325a5e2483038f82d2303a9de3a007be5d.zip |
Kernel: Move process coredump metadata modification to the prctl syscall
-rw-r--r-- | Kernel/API/Syscall.h | 1 | ||||
-rw-r--r-- | Kernel/API/prctl_numbers.h | 1 | ||||
-rw-r--r-- | Kernel/Process.h | 1 | ||||
-rw-r--r-- | Kernel/Syscalls/prctl.cpp | 15 | ||||
-rw-r--r-- | Kernel/Syscalls/process.cpp | 15 | ||||
-rw-r--r-- | Userland/DevTools/UserspaceEmulator/Emulator.h | 1 | ||||
-rw-r--r-- | Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp | 18 | ||||
-rw-r--r-- | Userland/Libraries/LibC/assert.cpp | 3 |
8 files changed, 17 insertions, 38 deletions
diff --git a/Kernel/API/Syscall.h b/Kernel/API/Syscall.h index 4d32782730..70c68838ca 100644 --- a/Kernel/API/Syscall.h +++ b/Kernel/API/Syscall.h @@ -155,7 +155,6 @@ enum class NeedsBigProcessLock { S(scheduler_set_parameters, NeedsBigProcessLock::No) \ S(sendfd, NeedsBigProcessLock::No) \ S(sendmsg, NeedsBigProcessLock::Yes) \ - S(set_coredump_metadata, NeedsBigProcessLock::No) \ S(set_mmap_name, NeedsBigProcessLock::Yes) \ S(set_process_name, NeedsBigProcessLock::No) \ S(set_thread_name, NeedsBigProcessLock::No) \ diff --git a/Kernel/API/prctl_numbers.h b/Kernel/API/prctl_numbers.h index 68042deb25..4c5d1603e3 100644 --- a/Kernel/API/prctl_numbers.h +++ b/Kernel/API/prctl_numbers.h @@ -10,3 +10,4 @@ #define PR_GET_DUMPABLE 2 #define PR_SET_NO_NEW_SYSCALL_REGION_ANNOTATIONS 3 #define PR_GET_NO_NEW_SYSCALL_REGION_ANNOTATIONS 4 +#define PR_SET_COREDUMP_METADATA_VALUE 5 diff --git a/Kernel/Process.h b/Kernel/Process.h index 755b0fea9c..57dd5c1afa 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -439,7 +439,6 @@ public: ErrorOr<FlatPtr> sys$disown(ProcessID); ErrorOr<FlatPtr> sys$allocate_tls(Userspace<char const*> initial_data, size_t); ErrorOr<FlatPtr> sys$prctl(int option, FlatPtr arg1, FlatPtr arg2); - ErrorOr<FlatPtr> sys$set_coredump_metadata(Userspace<Syscall::SC_set_coredump_metadata_params const*>); ErrorOr<FlatPtr> sys$anon_create(size_t, int options); ErrorOr<FlatPtr> sys$statvfs(Userspace<Syscall::SC_statvfs_params const*> user_params); ErrorOr<FlatPtr> sys$fstatvfs(int fd, statvfs* buf); diff --git a/Kernel/Syscalls/prctl.cpp b/Kernel/Syscalls/prctl.cpp index 678938ecc3..c76cec8580 100644 --- a/Kernel/Syscalls/prctl.cpp +++ b/Kernel/Syscalls/prctl.cpp @@ -25,7 +25,7 @@ ErrorOr<FlatPtr> Process::sys$prctl(int option, FlatPtr arg1, [[maybe_unused]] F return address_space().with([&](auto& space) -> ErrorOr<FlatPtr> { return space->enforces_syscall_regions(); }); - case PR_SET_NO_NEW_SYSCALL_REGION_ANNOTATIONS: + case PR_SET_NO_NEW_SYSCALL_REGION_ANNOTATIONS: { if (arg1 != 0 && arg1 != 1) return EINVAL; bool prohibit_new_annotated_syscall_regions = (arg1 == 1); @@ -38,6 +38,19 @@ ErrorOr<FlatPtr> Process::sys$prctl(int option, FlatPtr arg1, [[maybe_unused]] F }); return 0; } + case PR_SET_COREDUMP_METADATA_VALUE: { + auto params = TRY(copy_typed_from_user<Syscall::SC_set_coredump_metadata_params>(arg1)); + if (params.key.length == 0 || params.key.length > 16 * KiB) + return EINVAL; + if (params.value.length > 16 * KiB) + return EINVAL; + auto key = TRY(try_copy_kstring_from_user(params.key)); + auto value = TRY(try_copy_kstring_from_user(params.value)); + TRY(set_coredump_property(move(key), move(value))); + return 0; + } + } + return EINVAL; }); } diff --git a/Kernel/Syscalls/process.cpp b/Kernel/Syscalls/process.cpp index e2922dec9d..af4baea820 100644 --- a/Kernel/Syscalls/process.cpp +++ b/Kernel/Syscalls/process.cpp @@ -52,19 +52,4 @@ ErrorOr<FlatPtr> Process::sys$set_process_name(Userspace<char const*> user_name, return 0; } -ErrorOr<FlatPtr> Process::sys$set_coredump_metadata(Userspace<Syscall::SC_set_coredump_metadata_params const*> user_params) -{ - VERIFY_NO_PROCESS_BIG_LOCK(this); - auto params = TRY(copy_typed_from_user(user_params)); - - if (params.key.length == 0 || params.key.length > 16 * KiB) - return EINVAL; - if (params.value.length > 16 * KiB) - return EINVAL; - auto key = TRY(try_copy_kstring_from_user(params.key)); - auto value = TRY(try_copy_kstring_from_user(params.value)); - TRY(set_coredump_property(move(key), move(value))); - return 0; -} - } diff --git a/Userland/DevTools/UserspaceEmulator/Emulator.h b/Userland/DevTools/UserspaceEmulator/Emulator.h index c08be6e9c3..6a911466db 100644 --- a/Userland/DevTools/UserspaceEmulator/Emulator.h +++ b/Userland/DevTools/UserspaceEmulator/Emulator.h @@ -225,7 +225,6 @@ private: int virt$scheduler_set_parameters(FlatPtr); int virt$sendfd(int, int); int virt$sendmsg(int sockfd, FlatPtr msg_addr, int flags); - int virt$set_coredump_metadata(FlatPtr address); int virt$set_mmap_name(FlatPtr); int virt$set_process_name(FlatPtr buffer, int size); int virt$set_thread_name(pid_t, FlatPtr, size_t); diff --git a/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp b/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp index 93909afc52..f7ba559d3a 100644 --- a/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp +++ b/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp @@ -208,8 +208,6 @@ u32 Emulator::virt_syscall(u32 function, u32 arg1, u32 arg2, u32 arg3) return virt$sendfd(arg1, arg2); case SC_sendmsg: return virt$sendmsg(arg1, arg2, arg3); - case SC_set_coredump_metadata: - return virt$set_coredump_metadata(arg1); case SC_set_mmap_name: return virt$set_mmap_name(arg1); case SC_set_process_name: @@ -397,22 +395,6 @@ int Emulator::virt$rename(FlatPtr params_addr) return syscall(SC_rename, ¶ms); } -int Emulator::virt$set_coredump_metadata(FlatPtr params_addr) -{ - Syscall::SC_set_coredump_metadata_params params; - mmu().copy_from_vm(¶ms, params_addr, sizeof(params)); - - auto key = mmu().copy_buffer_from_vm((FlatPtr)params.key.characters, params.key.length); - params.key.characters = (char const*)key.data(); - params.key.length = key.size(); - - auto value = mmu().copy_buffer_from_vm((FlatPtr)params.value.characters, params.value.length); - params.value.characters = (char const*)value.data(); - params.value.length = value.size(); - - return syscall(SC_set_coredump_metadata, ¶ms); -} - int Emulator::virt$dbgputstr(FlatPtr characters, int length) { auto buffer = mmu().copy_buffer_from_vm(characters, length); diff --git a/Userland/Libraries/LibC/assert.cpp b/Userland/Libraries/LibC/assert.cpp index 31145f26eb..75d40ef47d 100644 --- a/Userland/Libraries/LibC/assert.cpp +++ b/Userland/Libraries/LibC/assert.cpp @@ -5,6 +5,7 @@ */ #include <AK/Format.h> +#include <Kernel/API/prctl_numbers.h> #include <assert.h> #include <stdio.h> #include <stdlib.h> @@ -29,7 +30,7 @@ void __assertion_failed(char const* msg) { "assertion", strlen("assertion") }, { msg, strlen(msg) }, }; - syscall(SC_set_coredump_metadata, ¶ms); + syscall(SC_prctl, PR_SET_COREDUMP_METADATA_VALUE, ¶ms, nullptr); abort(); } } |