From: Thomas Gleixner <tglx@kernel.org>
To: Daniel Wade <danjwade95@gmail.com>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Darren Hart <dvhart@infradead.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>,
Andre Almeida <andrealmeid@igalia.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Kyle Zeng <kylebot@openai.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] futex/pi: Reject owners that have no mm
Date: Mon, 30 Nov 2026 15:00:46 +0100 [thread overview]
Message-ID: <87h5gyqv01.ffs@fw13> (raw)
In-Reply-To: <20261116132622.34793-1-danjwade95@gmail.com>
On Mon, Nov 16 2026 at 23:56, Daniel Wade wrote:
> 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.
> 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.
Indeed.
> 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.
That's not really relevant because that's just a subsequent failure.
> Module auto-loading starts usermode helpers on behalf of ordinary
> users, so an unprivileged task reaches this.
> 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.
That comment is confusing at best.
> + */
> + if (unlikely(!p->mm)) {
> + raw_spin_unlock_irq(&p->pi_lock);
> + put_task_struct(p);
> + return -EPERM;
> + }
Why putting this into the pi_lock held region? p->pi_lock protects
nothing here and the access to p->mm is racy in any case and will
trigger KCSAN splats.
So the below is sufficient.
Thanks,
tglx
---
--- a/kernel/futex/pi.c
+++ b/kernel/futex/pi.c
@@ -473,7 +473,13 @@ static int attach_to_pi_owner(u32 __user
if (!p)
return handle_exit_race(uaddr, uval);
- if (unlikely(p->flags & PF_KTHREAD)) {
+ /*
+ * Don't attach to kernel threads or user mode helpers without mm. The
+ * access to p->mm is racy as the mm could be swapped right at this
+ * moment, but the only relevant information at this point is whether
+ * it's NULL or not.
+ */
+ if (unlikely(p->flags & PF_KTHREAD || !data_race(p->mm))) {
put_task_struct(p);
return -EPERM;
}
next prev parent reply other threads:[~2026-11-30 14:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 13:26 [PATCH] futex/pi: Reject owners that have no mm Daniel Wade
2026-11-30 14:00 ` Thomas Gleixner [this message]
2026-12-01 20:31 ` Christian Brauner
2026-12-01 21:25 ` Thomas Gleixner
2026-12-01 23:42 ` Thomas Gleixner
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=87h5gyqv01.ffs@fw13 \
--to=tglx@kernel.org \
--cc=andrealmeid@igalia.com \
--cc=bigeasy@linutronix.de \
--cc=danjwade95@gmail.com \
--cc=dave@stgolabs.net \
--cc=dvhart@infradead.org \
--cc=kylebot@openai.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.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