* [PATCH] futex/pi: Reject owners that have no mm
@ 2026-11-16 13:26 Daniel Wade
0 siblings, 0 replies; only message in thread
From: Daniel Wade @ 2026-11-16 13:26 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Peter Zijlstra, Darren Hart
Cc: Davidlohr Bueso, Andre Almeida, Sebastian Andrzej Siewior,
Kyle Zeng, linux-kernel
attach_to_pi_owner() attaches PI state to the task named in the futex word
and rejects kernel threads, which cannot own a user space futex.
A usermode helper thread runs with PF_KTHREAD cleared and acquires an mm at
exec(). While it is in that state, any task that can see its TID can name
it as the owner of a shared PI futex. Commit 59b3732f95dd ("futex/pi:
Reject cross-mm private futex owners") compares the owner mm with the
waiter mm, which applies to private keys only.
The helper then execs or exits, exit_pi_state_list() takes a reference on
the private hash of current->mm, and futex_private_hash() dereferences a
NULL mm. The oops path calls do_exit(), which runs the futex cleanup again
and blocks on the futex exit_mutex, so the thread stays there and with
preemptible RCU grace periods stop completing. Module auto-loading starts
usermode helpers on behalf of ordinary users, so an unprivileged task
reaches this.
Reject an owner that has no mm with -EPERM, as for a kernel thread, after
the futex state check so that an exited task still goes through
handle_exit_race().
Fixes: 80367ad01d93 ("futex: Add basic infrastructure for local task local hash")
Signed-off-by: Daniel Wade <danjwade95@gmail.com>
Cc: stable@vger.kernel.org
---
Tested on mainline b3dfbde62cf1 (kernel/futex identical to v7.4-rc3),
x86-64 with KASAN and lockdep, 2 vCPUs under KVM, as an ordinary user.
Without the patch a usermode helper accepted PI ownership 130 times, with
no EPERM refusal, and the kernel oopsed 22 s in:
Oops: stack segment: 0000 [#1] SMP KASAN NOPTI
RIP: 0010:futex_private_hash+0x4c/0x2b0
Call Trace:
futex_exit_exec_release
mm_exit_exec_release
begin_new_exec
call_usermodehelper_exec_async
after which the kworker never exited and RCU stall warnings repeated. With
the patch: 201472 refusals, 5822 owners that do have an mm still accepted,
no oops and no stall.
Not tested on other architectures.
kernel/futex/pi.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/kernel/futex/pi.c b/kernel/futex/pi.c
index 98f1b962e59a..77e88dd5dc22 100644
--- a/kernel/futex/pi.c
+++ b/kernel/futex/pi.c
@@ -515,6 +515,18 @@ static int attach_to_pi_owner(u32 __user *uaddr, u32 uval, union futex_key *key,
return ret;
}
+ /*
+ * A usermode helper thread runs with PF_KTHREAD cleared and acquires
+ * an mm at exec(), so the kernel thread test above lets it through.
+ * Its exec() or exit() cleanup runs exit_pi_state_list(), which uses
+ * current->mm.
+ */
+ if (unlikely(!p->mm)) {
+ raw_spin_unlock_irq(&p->pi_lock);
+ put_task_struct(p);
+ return -EPERM;
+ }
+
if (IS_ENABLED(CONFIG_MMU) && futex_key_is_private(key)) {
/*
* A private futex key holds a pointer to the waiter's mm
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-16 13:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 13:26 [PATCH] futex/pi: Reject owners that have no mm Daniel Wade
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®