Skip to content

Commit c2f7d08

Browse files
avaginKAGA-KOKO
authored andcommitted
futex: Adjust absolute futex timeouts with per time namespace offset
For all commands except FUTEX_WAIT, the timeout is interpreted as an absolute value. This absolute value is inside the task's time namespace and has to be converted to the host's time. Fixes: 5a590f3 ("posix-clocks: Wire up clock_gettime() with timens offsets") Reported-by: Hans van der Laan <[email protected]> Signed-off-by: Andrei Vagin <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Dmitry Safonov <[email protected]> Cc: <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 270315b commit c2f7d08

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

kernel/futex.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <linux/freezer.h>
4040
#include <linux/memblock.h>
4141
#include <linux/fault-inject.h>
42+
#include <linux/time_namespace.h>
4243

4344
#include <asm/futex.h>
4445

@@ -3797,6 +3798,8 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
37973798
t = timespec64_to_ktime(ts);
37983799
if (cmd == FUTEX_WAIT)
37993800
t = ktime_add_safe(ktime_get(), t);
3801+
else if (!(op & FUTEX_CLOCK_REALTIME))
3802+
t = timens_ktime_to_host(CLOCK_MONOTONIC, t);
38003803
tp = &t;
38013804
}
38023805
/*
@@ -3989,6 +3992,8 @@ SYSCALL_DEFINE6(futex_time32, u32 __user *, uaddr, int, op, u32, val,
39893992
t = timespec64_to_ktime(ts);
39903993
if (cmd == FUTEX_WAIT)
39913994
t = ktime_add_safe(ktime_get(), t);
3995+
else if (!(op & FUTEX_CLOCK_REALTIME))
3996+
t = timens_ktime_to_host(CLOCK_MONOTONIC, t);
39923997
tp = &t;
39933998
}
39943999
if (cmd == FUTEX_REQUEUE || cmd == FUTEX_CMP_REQUEUE ||

0 commit comments

Comments
 (0)