From 10e912d68c47d4575c3030948fbcf3d11ba4a30d Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Sat, 1 Aug 2020 18:06:29 -0700 Subject: [PATCH] Kernel: Use Userspace in sched_setparam syscall Note: I switched from copying the single element out of the sched_param struct, to copy struct it self as it is identical in functionality. This way the types match up nicer with the Userpace api's and it conforms to the conventions used in other syscalls. --- Kernel/Process.h | 2 +- Kernel/Syscalls/sched.cpp | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Kernel/Process.h b/Kernel/Process.h index 5ecaa9cf6cf..f5f9bbfa198 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -291,7 +291,7 @@ public: int sys$setsockopt(const Syscall::SC_setsockopt_params*); int sys$getsockname(const Syscall::SC_getsockname_params*); int sys$getpeername(const Syscall::SC_getpeername_params*); - int sys$sched_setparam(pid_t pid, const struct sched_param* param); + int sys$sched_setparam(pid_t pid, Userspace); int sys$sched_getparam(pid_t pid, struct sched_param* param); int sys$create_thread(void* (*)(void*), const Syscall::SC_create_thread_params*); void sys$exit_thread(void*); diff --git a/Kernel/Syscalls/sched.cpp b/Kernel/Syscalls/sched.cpp index 79ad45d5997..13f4cf2a07e 100644 --- a/Kernel/Syscalls/sched.cpp +++ b/Kernel/Syscalls/sched.cpp @@ -48,14 +48,14 @@ int Process::sys$donate(int tid) return 0; } -int Process::sys$sched_setparam(int tid, const struct sched_param* param) +int Process::sys$sched_setparam(int tid, Userspace user_param) { REQUIRE_PROMISE(proc); - if (!validate_read_typed(param)) + if (!validate_read_typed(user_param)) return -EFAULT; - int desired_priority; - copy_from_user(&desired_priority, ¶m->sched_priority); + struct sched_param desired_param; + copy_from_user(&desired_param, user_param); InterruptDisabler disabler; auto* peer = Thread::current(); @@ -68,10 +68,11 @@ int Process::sys$sched_setparam(int tid, const struct sched_param* param) if (!is_superuser() && m_euid != peer->process().m_uid && m_uid != peer->process().m_uid) return -EPERM; - if (desired_priority < THREAD_PRIORITY_MIN || desired_priority > THREAD_PRIORITY_MAX) + if (desired_param.sched_priority < THREAD_PRIORITY_MIN || + desired_param.sched_priority > THREAD_PRIORITY_MAX) return -EINVAL; - peer->set_priority((u32)desired_priority); + peer->set_priority((u32)desired_param.sched_priority); return 0; }