From: Chengfeng Ye <dg573847474@gmail.com>
To: tglx@kernel.org, mingo@redhat.com, peterz@infradead.org,
linux-kernel@vger.kernel.org
Cc: dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com,
bigeasy@linutronix.de, security@kernel.org,
Chengfeng Ye <dg573847474@gmail.com>
Subject: [PATCH] futex: fix NUMA node publication race causing missed wakeups
Date: Tue, 3 Mar 2026 03:01:00 +0000 [thread overview]
Message-ID: <20260303030100.819744-1-dg573847474@gmail.com> (raw)
get_futex_key() publishes the FUTEX2_NUMA node side word in userspace.
The publication path used a non-atomic read/compute/write sequence, so
concurrent callers could overwrite each other during initialization.
This race can make concurrent operations on the same futex derive
different node values while the NUMA hint is being initialized,
resulting in inconsistent futex keying between wait and wake sides.
In practice this can lead to missed wakeups; at user level, missed
wakeups can manifest as threads waiting indefinitely
(application-level deadlock/hang).
PoC description (see Link below):
- two threads repeatedly exercising FUTEX2_NUMA wait/wake on the
same futex,
- waiter and waker pinned to CPUs from different NUMA nodes,
- waker continuously issuing wake calls while waiter performs
10-second timed waits.
PoC output on unpatched kernel (wake sigal missed and waiter timeout):
- observed on Linux v7.0-rc2 running in qemu-system-x86_64 with
4 vCPUs
Using CPU 0 (waiter) and CPU 2 (waker) from different NUMA nodes
[TRIGGER EVENT #1] iter=38 timed out (futex.node=1)
[TRIGGER EVENT #2] iter=85 timed out (futex.node=1)
[TRIGGER EVENT #3] iter=95 timed out (futex.node=1)
Fix by making node-hint publication publish-once via atomic cmpxchg on
naddr (FUTEX_NO_NODE -> computed node), retrying transient -EAGAIN,
and adopting/validating the winner value on contention.
Fixes: c042c505210d ("futex: Implement FUTEX2_MPOL")
Link: https://gist.github.com/Ychame/d4a5e95401a471f4211a751734b5d164
Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>
---
kernel/futex/core.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/kernel/futex/core.c b/kernel/futex/core.c
index cf7e610eac42..d45612b36e30 100644
--- a/kernel/futex/core.c
+++ b/kernel/futex/core.c
@@ -596,13 +596,29 @@ int get_futex_key(u32 __user *uaddr, unsigned int flags, union futex_key *key,
if (flags & FLAGS_NUMA) {
u32 __user *naddr = (void *)uaddr + size / 2;
+ u32 old_node;
if (node == FUTEX_NO_NODE) {
node = numa_node_id();
node_updated = true;
}
- if (node_updated && put_user_inline(node, naddr))
- return -EFAULT;
+ if (node_updated) {
+retry_numa_node:
+ err = futex_cmpxchg_value_locked(&old_node, naddr,
+ FUTEX_NO_NODE, (u32)node);
+ if (err == -EAGAIN) {
+ cond_resched();
+ goto retry_numa_node;
+ }
+ if (err)
+ return err;
+ if (old_node != FUTEX_NO_NODE) {
+ node = old_node;
+ if ((unsigned int)node >= MAX_NUMNODES ||
+ !node_possible(node))
+ return -EINVAL;
+ }
+ }
}
key->both.node = node;
--
2.25.1
next reply other threads:[~2026-03-03 3:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-03 3:01 Chengfeng Ye [this message]
2026-03-12 9:37 ` Sebastian Andrzej Siewior
2026-03-12 9:55 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260303030100.819744-1-dg573847474@gmail.com \
--to=dg573847474@gmail.com \
--cc=andrealmeid@igalia.com \
--cc=bigeasy@linutronix.de \
--cc=dave@stgolabs.net \
--cc=dvhart@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=security@kernel.org \
--cc=tglx@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®