summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/waitid.cpp
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2020-09-11 21:11:07 -0600
committerAndreas Kling <kling@serenityos.org>2020-09-13 21:19:15 +0200
commitc8d9f1b9c920e0314bb9ca67f183c8df743e845a (patch)
tree773e9fb30d26602598ba309291b8e6d2e80475e6 /Kernel/Syscalls/waitid.cpp
parent7d1b8417bdf5d2818d1c9d310786cdf59650b104 (diff)
downloadserenity-c8d9f1b9c920e0314bb9ca67f183c8df743e845a.zip
Kernel: Make copy_to/from_user safe and remove unnecessary checks
Since the CPU already does almost all necessary validation steps for us, we don't really need to attempt to do this. Doing it ourselves doesn't really work very reliably, because we'd have to account for other processors modifying virtual memory, and we'd have to account for e.g. pages not being able to be allocated due to insufficient resources. So change the copy_to/from_user (and associated helper functions) to use the new safe_memcpy, which will return whether it succeeded or not. The only manual validation step needed (which the CPU can't perform for us) is making sure the pointers provided by user mode aren't pointing to kernel mappings. To make it easier to read/write from/to either kernel or user mode data add the UserOrKernelBuffer helper class, which will internally either use copy_from/to_user or directly memcpy, or pass the data through directly using a temporary buffer on the stack. Last but not least we need to keep syscall params trivial as we need to copy them from/to user mode using copy_from/to_user.
Diffstat (limited to 'Kernel/Syscalls/waitid.cpp')
-rw-r--r--Kernel/Syscalls/waitid.cpp16
1 files changed, 4 insertions, 12 deletions
diff --git a/Kernel/Syscalls/waitid.cpp b/Kernel/Syscalls/waitid.cpp
index 41a0d7c12a..1b12c2a744 100644
--- a/Kernel/Syscalls/waitid.cpp
+++ b/Kernel/Syscalls/waitid.cpp
@@ -104,27 +104,19 @@ pid_t Process::sys$waitid(Userspace<const Syscall::SC_waitid_params*> user_param
REQUIRE_PROMISE(proc);
Syscall::SC_waitid_params params;
- if (!validate_read_and_copy_typed(&params, user_params))
- return -EFAULT;
-
- if (!validate_write_typed(params.infop))
+ if (!copy_from_user(&params, user_params))
return -EFAULT;
#ifdef PROCESS_DEBUG
- dbg() << "sys$waitid(" << params.idtype << ", " << params.id << ", " << params.infop.ptr() << ", " << params.options << ")";
+ dbg() << "sys$waitid(" << params.idtype << ", " << params.id << ", " << params.infop << ", " << params.options << ")";
#endif
auto siginfo_or_error = do_waitid(static_cast<idtype_t>(params.idtype), params.id, params.options);
if (siginfo_or_error.is_error())
return siginfo_or_error.error();
- // While we waited, the process lock was dropped. This gave other threads
- // the opportunity to mess with the memory. For example, it could free the
- // region, and map it to a region to which it has no write permissions.
- // Therefore, we need to re-validate the pointer.
- if (!validate_write_typed(params.infop))
- return -EFAULT;
- copy_to_user(params.infop, &siginfo_or_error.value());
+ if (!copy_to_user(params.infop, &siginfo_or_error.value()))
+ return -EFAULT;
return 0;
}