From b630e39fbb705b145fd940e85b491287d69de6b9 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Mon, 26 Apr 2021 17:22:04 +0200 Subject: Kernel: Check futex command if realtime clock is used --- Kernel/Syscalls/futex.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Kernel') diff --git a/Kernel/Syscalls/futex.cpp b/Kernel/Syscalls/futex.cpp index 89a801d073..33efb138fa 100644 --- a/Kernel/Syscalls/futex.cpp +++ b/Kernel/Syscalls/futex.cpp @@ -90,6 +90,12 @@ KResultOr Process::sys$futex(Userspace use Thread::BlockTimeout timeout; u32 cmd = params.futex_op & FUTEX_CMD_MASK; + + bool use_realtime_clock = (params.futex_op & FUTEX_CLOCK_REALTIME) != 0; + if (use_realtime_clock && cmd != FUTEX_WAIT && cmd != FUTEX_WAIT_BITSET) { + return ENOSYS; + } + switch (cmd) { case FUTEX_WAIT: case FUTEX_WAIT_BITSET: @@ -99,8 +105,8 @@ KResultOr Process::sys$futex(Userspace use auto timeout_time = copy_time_from_user(params.timeout); if (!timeout_time.has_value()) return EFAULT; - clockid_t clock_id = (params.futex_op & FUTEX_CLOCK_REALTIME) ? CLOCK_REALTIME_COARSE : CLOCK_MONOTONIC_COARSE; bool is_absolute = cmd != FUTEX_WAIT; + clockid_t clock_id = use_realtime_clock ? CLOCK_REALTIME_COARSE : CLOCK_MONOTONIC_COARSE; timeout = Thread::BlockTimeout(is_absolute, &timeout_time.value(), nullptr, clock_id); } if (cmd == FUTEX_WAIT_BITSET && params.val3 == FUTEX_BITSET_MATCH_ANY) -- cgit v1.2.3