Skip to contentSkip to conversation

futex: Drop CLONE_THREAD requirement for private default hash alloc

PATCH In review Mohamed Ayman 3 participants 4 messages May 2

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 futex: Drop CLONE_THREAD requirement for private default hash alloc

From: Davidlohr Bueso <[email protected]>

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_VM.

---
 kernel/fork.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
kernel/fork.c +5 -7
index f1ad69c6dc2d..5f3fdfdb14c7 100644
@@ -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)
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 18 lines · On Sat, 2 May 2026 18:57:29 +0300 Mohamed Ayman…

From: Davidlohr Bueso <[email protected]>

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_VM.

Quoted 5 lines

I hate to get all bureaucratic, but....

Given what you've sent and from my reading of the security@ and linux-kernel@ lists,

- I can't find a patch from Davidlohr which looks like this one - I can't figure out where you got that from.

- I can't find any code from Linus which would lead to the addition of his Signed-off-by:. I don't know where you got that from either.

- Let's cc the author of the Fixes target, Sebastian?

I'd like to have this metadata tightened up, please - so a reader of this patch can understand who did & said what and when and why.

Thanks.

Quoted 35 lines
 kernel/fork.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
kernel/fork.c +5 -7
index f1ad69c6dc2d..5f3fdfdb14c7 100644
@@ -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)
Signature · 1 line
2.34.1
#2 lore raw

Hi all,
Please ignore this patch. It was sent in error

Regards,

Quoted 85 lines · Andrew Morton
Quoted 12 lines · On Sat, 2 May 2026 18:57:29 +0300 Mohamed Ayman <…

From: Davidlohr Bueso <[email protected]>

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.

Quoted 7 lines

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_VM.

Link:

https://lore.kernel.org/all/CAL_bE8LsmCQ-FAtYDuwbJhOkt9p2wwYQwAbMh=PifC=VsiBM6A@mail.gmail.com/
[0]

Quoted 4 lines
Fixes d9b05321e21e ("futex: Move futex_hash_free() back to __mmput()")

I hate to get all bureaucratic, but....

Given what you've sent and from my reading of the security@ and linux-kernel@ lists,

- I can't find a patch from Davidlohr which looks like this one - I can't figure out where you got that from.

- I can't find any code from Linus which would lead to the addition of his Signed-off-by:. I don't know where you got that from either.

- Let's cc the author of the Fixes target, Sebastian?

I'd like to have this metadata tightened up, please - so a reader of this patch can understand who did & said what and when and why.

Thanks.

kernel/fork.c static void rv_task_fork(struct task_struct *p) · line 1954

Quoted 12 lines
 kernel/fork.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
kernel/fork.c +0 -1
index f1ad69c6dc2d..5f3fdfdb14c7 100644
@@ -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))

Quoted 11 lines
kernel/fork.c +5 -2
-             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;
 }
 
 /*

kernel/fork.c __latent_entropy struct task_struct *copy_process( · line 2384

Quoted 5 lines
kernel/fork.c +0 -2
@@ -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

Quoted 7 lines
kernel/fork.c +0 -3
-      * thread spawns.
-      */
      if (need_futex_hash_allocate_default(clone_flags)) {
              retval = futex_hash_allocate_default();
              if (retval)
--

2.34.1

#3 lore raw
In reply to Andrew Morton
Quoted 6 lines · Andrew Morton

- I can't find a patch from Davidlohr which looks like this one - I can't figure out where you got that from.

- I can't find any code from Linus which would lead to the addition of his Signed-off-by:. I don't know where you got that from either.

It looks to be just a re-send from the kernel git tree (commit
ee9dce44362b: "futex: Drop CLONE_THREAD requirement for private default hash alloc").

People who use git-send-email by mistalke often end up re-sending other peoples patches.

And that commit came from

    https://lore.kernel.org/all/[email protected]/

except I fixed the "from an earlier CLONE_THREAD" in the commit message to be about CLONE_VM when I applied it (as per the thread there)

Linus