From e1db8094b61aae6493cb10426b09d5f4c7177e8f Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Fri, 12 Feb 2021 18:23:28 +0100 Subject: [PATCH] Kernel: Avoid casting arbitrary user-controlled int to enum This caused a load-invalid-value warning by KUBSan. Found by fuzz-syscalls. Can be reproduced by running this in the Shell: $ syscall waitid [ 1234 ] --- Kernel/Syscalls/waitid.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Kernel/Syscalls/waitid.cpp b/Kernel/Syscalls/waitid.cpp index eeb471f947..d9dc09f509 100644 --- a/Kernel/Syscalls/waitid.cpp +++ b/Kernel/Syscalls/waitid.cpp @@ -31,15 +31,6 @@ namespace Kernel { KResultOr Process::do_waitid(idtype_t idtype, int id, int options) { - switch (idtype) { - case P_ALL: - case P_PID: - case P_PGID: - break; - default: - return EINVAL; - } - KResultOr result = KResult(KSuccess); if (Thread::current()->block({}, options, idtype, id, result).was_interrupted()) return EINTR; @@ -55,6 +46,15 @@ pid_t Process::sys$waitid(Userspace user_param if (!copy_from_user(¶ms, user_params)) return -EFAULT; + switch (params.idtype) { + case P_ALL: + case P_PID: + case P_PGID: + break; + default: + return EINVAL; + } + dbgln_if(PROCESS_DEBUG, "sys$waitid({}, {}, {}, {})", params.idtype, params.id, params.infop, params.options); auto siginfo_or_error = do_waitid(static_cast(params.idtype), params.id, params.options);