Skip to content

Commit ee9dce4

Browse files
Davidlohr Buesotorvalds
authored andcommitted
futex: Drop CLONE_THREAD requirement for private default hash alloc
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. Link: https://lore.kernel.org/all/CAL_bE8LsmCQ-FAtYDuwbJhOkt9p2wwYQwAbMh=PifC=VsiBM6A@mail.gmail.com/ [0] Fixes: d9b0532 ("futex: Move futex_hash_free() back to __mmput()") Reported-by: Yiming Qian <yimingqian591@gmail.com> Signed-off-by: Davidlohr Bueso <dave@stgolabs.net> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent bb1d73f commit ee9dce4

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

kernel/fork.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,9 +1951,11 @@ static void rv_task_fork(struct task_struct *p)
19511951

19521952
static bool need_futex_hash_allocate_default(u64 clone_flags)
19531953
{
1954-
if ((clone_flags & (CLONE_THREAD | CLONE_VM)) != (CLONE_THREAD | CLONE_VM))
1955-
return false;
1956-
return true;
1954+
/*
1955+
* Allocate a default futex hash for any sibling that will
1956+
* share the parent's mm, except vfork.
1957+
*/
1958+
return (clone_flags & (CLONE_VM | CLONE_VFORK)) == CLONE_VM;
19571959
}
19581960

19591961
/*
@@ -2380,10 +2382,6 @@ __latent_entropy struct task_struct *copy_process(
23802382
if (retval)
23812383
goto bad_fork_cancel_cgroup;
23822384

2383-
/*
2384-
* Allocate a default futex hash for the user process once the first
2385-
* thread spawns.
2386-
*/
23872385
if (need_futex_hash_allocate_default(clone_flags)) {
23882386
retval = futex_hash_allocate_default();
23892387
if (retval)

0 commit comments

Comments
 (0)