]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-futex: Check for proper FUTEX_CLOCK_REALTIME usage
authorMarco Schlumpp <marco@unikraft.io>
Mon, 17 Apr 2023 08:04:04 +0000 (10:04 +0200)
committerUnikraft <monkey@unikraft.io>
Sun, 7 May 2023 12:18:32 +0000 (12:18 +0000)
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 <marco@unikraft.io>
Reviewed-by: Adina Smeu <adina.smeu@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #758

lib/posix-futex/futex.c

index d8eace3210358f78359b7561c68836cdeca02334..f8f579640b0c75dcf38835fb8421ca2f970cbd36 100644 (file)
@@ -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