Skip to content

Commit e52c3c7

Browse files
peterz@infradead.orgopsiff
authored andcommitted
futex: FLAGS_STRICT
mainline inclusion from mainline-v6.7-rc1 category: feature The current semantics for futex_wake() are a bit loose, specifically asking for 0 futexes to be woken actually gets you 1. Adding a !nr check to sys_futex_wake() makes that it would return 0 for unaligned futex words, because that check comes in the shared futex_wake() function. Adding the !nr check there, would affect the legacy sys_futex() semantics. Hence frob a flag :-( Suggested-by: André Almeida <andrealmeid@igalia.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20230921105248.048643656@noisy.programming.kicks-ass.net (cherry picked from commit 43adf84) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent f5ef5f3 commit e52c3c7

3 files changed

Lines changed: 15 additions & 11 deletions

File tree

kernel/futex/futex.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,26 @@
1717
* Futex flags used to encode options to functions and preserve them across
1818
* restarts.
1919
*/
20-
#define FLAGS_SIZE_8 0x00
21-
#define FLAGS_SIZE_16 0x01
22-
#define FLAGS_SIZE_32 0x02
23-
#define FLAGS_SIZE_64 0x03
20+
#define FLAGS_SIZE_8 0x0000
21+
#define FLAGS_SIZE_16 0x0001
22+
#define FLAGS_SIZE_32 0x0002
23+
#define FLAGS_SIZE_64 0x0003
2424

25-
#define FLAGS_SIZE_MASK 0x03
25+
#define FLAGS_SIZE_MASK 0x0003
2626

2727
#ifdef CONFIG_MMU
28-
# define FLAGS_SHARED 0x10
28+
# define FLAGS_SHARED 0x0010
2929
#else
3030
/*
3131
* NOMMU does not have per process address space. Let the compiler optimize
3232
* code away.
3333
*/
34-
# define FLAGS_SHARED 0x00
34+
# define FLAGS_SHARED 0x0000
3535
#endif
36-
#define FLAGS_CLOCKRT 0x20
37-
#define FLAGS_HAS_TIMEOUT 0x40
38-
#define FLAGS_NUMA 0x80
36+
#define FLAGS_CLOCKRT 0x0020
37+
#define FLAGS_HAS_TIMEOUT 0x0040
38+
#define FLAGS_NUMA 0x0080
39+
#define FLAGS_STRICT 0x0100
3940

4041
/* FUTEX_ to FLAGS_ */
4142
static inline unsigned int futex_to_flags(unsigned int op)

kernel/futex/syscalls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ SYSCALL_DEFINE4(futex_wake,
361361
if (!futex_validate_input(flags, mask))
362362
return -EINVAL;
363363

364-
return futex_wake(uaddr, flags, nr, mask);
364+
return futex_wake(uaddr, FLAGS_STRICT | flags, nr, mask);
365365
}
366366

367367
#ifdef CONFIG_COMPAT

kernel/futex/waitwake.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ int futex_wake(u32 __user *uaddr, unsigned int flags, int nr_wake, u32 bitset)
155155
if (unlikely(ret != 0))
156156
return ret;
157157

158+
if ((flags & FLAGS_STRICT) && !nr_wake)
159+
return 0;
160+
158161
hb = futex_hash(&key);
159162

160163
/* Make sure we really have tasks to wakeup */

0 commit comments

Comments
 (0)