futex: fix hb lock mismatch in futex_wait_requeue_pi() and CLONE_VFORK hash init
Subsystems (4)
PATCH 1/1 futex: fix hb lock mismatch in futex_wait_requeue_pi() and CLONE_VFORK hash init
Fix two issues in futex and fork initialization:
1. In futex_wait_requeue_pi(), if futex_wait_queue() returns with q.lock_ptr updated tohb2's lock after a requeue timeout or signal race, unlocking the original hb1 lock instead of q.lock_ptr leaves hb2 locked and unlocks an unheld spinlock. Always unlock via q.lock_ptr.
2. In copy_mm() (kernel/fork.c), initialize mm->futex_phash properly when cloning so private futex hash state is consistent across CLONE_VFORK.
---
kernel/fork.c +2 -2
@@ -1996,9 +1996,9 @@ static bool need_futex_hash_allocate_default(u64 clone_flags) {/* * Allocate a default futex hash for any sibling that will -* share the parent's mm, except vfork. +* share the parent's mm. */ -return (clone_flags & (CLONE_VM |CLONE_VFORK )) ==CLONE_VM ; +return (clone_flags &CLONE_VM ) !=0 ; }/*
kernel/futex/requeue.c +5 -4
@@ -842,12 +842,13 @@ int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,switch (futex_requeue_pi_wakeup_sync (&q)) {case Q_REQUEUE_PI_IGNORE : { -CLASS (hbr, hbr)(&q.key); - auto hb = hbr.hb; +struct futex_hash_bucket *hb; +/* The waiter is still on uaddr1 */ -spin_lock (&hb->lock); +futex_q_lockptr_lock (&q); + hb = container_of(q.lock_ptr, struct futex_hash_bucket, lock); ret =handle_early_requeue_pi_wakeup (hb, &q, to); -spin_unlock (&hb->lock); +spin_unlock (q.lock_ptr); }break ;
André Almeida
reviewerHi Hui Peng,
Em 19/09/2026 19:17, Hui Peng escreveu:
Quoted 3 lines
Fix two issues in futex and fork initialization:
1. In
futex_wait_requeue_pi(), iffutex_wait_queue()returns with
I see an outdated comment with futex_wait_queue(), but I don't think this function exists anymore.
Quoted 8 lines
q.lock_ptr updated tohb2's lock after a requeue timeout or signal race, unlocking the original hb1 lock instead of q.lock_ptr leaves hb2 locked and unlocks an unheld spinlock. Always unlock via q.lock_ptr.
2. Incopy_mm()(kernel/fork.c), initializemm->futex_phashproperly when cloning so private futex hash state is consistent acrossCLONE_VFORK.
This part was already addressed:
Quoted 2 lines
Fixes e5c6828493b5 ("futex: Split out requeue")Assisted-by LLM
Please always double check in the current mainline code if the robots ideas are up to date.
Quoted 1 line
Signed-off-by Hui Peng <[email protected]>