From: Marco Schlumpp Date: Mon, 17 Apr 2023 08:04:04 +0000 (+0200) Subject: lib/posix-futex: Check for proper FUTEX_CLOCK_REALTIME usage X-Git-Tag: RELEASE-0.13.0~68 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=7ef5bbccffa6592a0d6da0efedd3c63366ba3cbb;p=unikraft%2Funikraft.git lib/posix-futex: Check for proper FUTEX_CLOCK_REALTIME usage The documentation specifies a list of operations which support this flag. This adds a check that explicitly rejects all invalid combinations and returns `ENOSYS` according to the documentation. Checkpatch-Ignore: ENOSYS Signed-off-by: Marco Schlumpp Reviewed-by: Adina Smeu Approved-by: Razvan Deaconescu Tested-by: Unikraft CI GitHub-Closes: #758 --- diff --git a/lib/posix-futex/futex.c b/lib/posix-futex/futex.c index d8eace321..f8f579640 100644 --- a/lib/posix-futex/futex.c +++ b/lib/posix-futex/futex.c @@ -277,13 +277,22 @@ UK_LLSYSCALL_R_DEFINE(int, futex, uint32_t *, uaddr, int, futex_op, uint32_t *, uaddr2, uint32_t, val3) { __nsec timeout_ns; + int cmd = futex_op & FUTEX_CMD_MASK; + + /* Reject invalid combinations of the realtime clock flag */ + if (futex_op & FUTEX_CLOCK_REALTIME && !( + cmd == FUTEX_WAIT || + cmd == FUTEX_WAIT_BITSET || + cmd == FUTEX_LOCK_PI2 || + cmd == FUTEX_WAIT_REQUEUE_PI)) + return -ENOSYS; /* * N.B. CLOCK_(MONOTONIC|REALTIME|...) are at the moment all the same in * Unikraft. Therefore, we can just use CLOCK_MONOTONIC for timeouts in * the following code. */ - switch (futex_op & FUTEX_CMD_MASK) { + switch (cmd) { case FUTEX_WAIT: /* * `timeout` is relative to "now" (whenever that is). To