From: Davidlohr Bueso <dave@stgolabs.net>
To: torvalds@linuxfoundation.org, tglx@kernel.org, mingo@redhat.com,
peterz@infradead.org
Cc: bigeasy@linutronix.de, yimingqian591@gmail.com,
dvhart@infradead.org, andrealmeid@igalia.com, dave@stgolabs.net,
linux-kernel@vger.kernel.org
Subject: [PATCH] futex: Drop CLONE_THREAD requirement for private default hash alloc
Date: Fri, 1 May 2026 12:41:23 -0700 [thread overview]
Message-ID: <20260501194123.948643-1-dave@stgolabs.net> (raw)
Currently need_futex_hash_allocate_default() depends on strict
pthread semantics, abusing CLONE_THREAD. This breaks the
non-concurrency assumptions when doing the mm->futex_ref pcpu
allocations, leading to bugs[0] when sharing the mm in other ways;
ie:
BUG: KASAN: slab-use-after-free in futex_hash_put
... where the +1 bias can end up on a percpu counter that mm->futex_ref
no longer points at.
Loosen the check to cover any CLONE_VM clone, except vfork(). Excluding
vfork keeps the existing paths untouched (no overhead), and we can't
race in the first place: either the parent is suspended and the child runs
alone, or mm->futex_ref is already allocated from an earlier CLONE_THREAD.
[0] https://lore.kernel.org/all/CAL_bE8LsmCQ-FAtYDuwbJhOkt9p2wwYQwAbMh=PifC=VsiBM6A@mail.gmail.com/
Fixes: d9b05321e21e ("futex: Move futex_hash_free() back to __mmput()")
Reported-by: Yiming Qian <yimingqian591@gmail.com>
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
---
kernel/fork.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/kernel/fork.c b/kernel/fork.c
index f1ad69c6dc2d..5f3fdfdb14c7 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1951,9 +1951,11 @@ static void rv_task_fork(struct task_struct *p)
static bool need_futex_hash_allocate_default(u64 clone_flags)
{
- if ((clone_flags & (CLONE_THREAD | CLONE_VM)) != (CLONE_THREAD | CLONE_VM))
- return false;
- return true;
+ /*
+ * Allocate a default futex hash for any sibling that will
+ * share the parent's mm, except vfork.
+ */
+ return (clone_flags & (CLONE_VM | CLONE_VFORK)) == CLONE_VM;
}
/*
@@ -2380,10 +2382,6 @@ __latent_entropy struct task_struct *copy_process(
if (retval)
goto bad_fork_cancel_cgroup;
- /*
- * Allocate a default futex hash for the user process once the first
- * thread spawns.
- */
if (need_futex_hash_allocate_default(clone_flags)) {
retval = futex_hash_allocate_default();
if (retval)
--
2.39.5
next reply other threads:[~2026-05-01 19:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-01 19:41 Davidlohr Bueso [this message]
2026-05-01 20:01 ` Linus Torvalds
2026-05-01 20:05 ` Davidlohr Bueso
2026-05-01 20:13 ` Linus Torvalds
2026-05-02 15:57 Mohamed Ayman
2026-05-02 17:24 ` Andrew Morton
2026-05-02 17:39 ` Linus Torvalds
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=20260501194123.948643-1-dave@stgolabs.net \
--to=dave@stgolabs.net \
--cc=andrealmeid@igalia.com \
--cc=bigeasy@linutronix.de \
--cc=dvhart@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@kernel.org \
--cc=torvalds@linuxfoundation.org \
--cc=yimingqian591@gmail.com \
/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®