Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH 6.18.y] futex: Fix private hash use-after-free on resize
@ 2026-11-30  6:13 Artem Dinaburg
  0 siblings, 0 replies; only message in thread
From: Artem Dinaburg @ 2026-11-30  6:13 UTC (permalink / raw)
  To: stable
  Cc: andrealmeid, dave, dvhart, linux-kernel, mason, mingo, paulmck,
	peterz, tglx

From: Chris Mason <mason@kernel.org>
Date: Thu, 1 Oct 2026 13:50:22 +0000

[ Upstream commit f35e3b5784221654f9cdbd6222275a7fa203f6c3 ]

poll_state_synchronize_rcu(mm->futex.phash.batches) is used by
futex_ref_drop() to check that a grace period has passed since the
current hash was published. This relies on batches referencing a grace
period which started after the hash pointer was assigned.

__futex_pivot_hash() sets mmph->batches before it replaces mmph->hash:

    scoped_guard(rcu) {
            mmph->batches = get_state_synchronize_rcu();
            rcu_assign_pointer(mmph->hash, new);
    }

The scoped_guard(rcu) doesn't stop new grace periods from starting, and
if one starts between those two assignments, futex_ref_drop() can move
forward while a reader still holds a pointer to the old hash.

Fix things by setting mmph->batches after assigning mmph->hash.  The
scoped_guard(rcu) isn't needed, so let's drop that as well.

Fixes: 56180dd20c19 ("futex: Use RCU-based per-CPU reference counting instead of rcuref_t")
Assisted-by: kres
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
Link: https://patch.msgid.link/20261001135022.2220288-1-mason@kernel.org
[ Backport to 6.18.y: 6.18 predates commit 1f7f4816b9b0 ("futex: Move
  futex related mm_struct data into a struct"), so use mm->futex_phash
  and mm->futex_batches instead of mmph->hash and mmph->batches. ]
Signed-off-by: Artem Dinaburg <artem@trailofbits.com>
---
Hi,

Please apply this to 6.18.y. It fixes CVE-2026-98788.

The upstream commit does not apply as-is because 6.18 still uses the
old mm_struct futex field names. The backport only renames those
fields; the code change is otherwise identical.

The fix has been in mainline since 7.3-rc6 and was backported to 7.2.y
in 7.2.10. Kernels 6.12.y and older do not contain 56180dd20c19 and
are not affected.

6.18.y already has the related futex fixes from 6.18.46 and 6.18.47:

  futex: Fix race in futex_pivot_pending() during private hash resize
  futex: Fix might_sleep() warning in futex_pivot_pending()
  futex: Avoid private hash use-after-free on final put
  futex: Fix race on the initial mm->futex.phash.ref allocation

None of them changes the ordering in __futex_pivot_hash(), so 6.18.y
still samples the RCU grace-period state before publishing the new
hash.

Compile-tested on 6.18.65 with CONFIG_FUTEX_PRIVATE_HASH=y.

I used an LLM to help adapt the patch and draft this email, and
reviewed the result myself.

Thanks,
Artem Dinaburg

 kernel/futex/core.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/kernel/futex/core.c b/kernel/futex/core.c
index e6fbeb2ac19014e08e636623d6cf2ba3a67c85f5..cb8cfa81d71ac4dc1cd4697624871e8d3bbd50dd 100644
--- a/kernel/futex/core.c
+++ b/kernel/futex/core.c
@@ -214,10 +214,12 @@ static bool __futex_pivot_hash(struct mm_struct *mm,
 		futex_rehash_private(fph, new);
 	}
 	new->state = FR_PERCPU;
-	scoped_guard(rcu) {
-		mm->futex_batches = get_state_synchronize_rcu();
-		rcu_assign_pointer(mm->futex_phash, new);
-	}
+	rcu_assign_pointer(mm->futex_phash, new);
+	/*
+	 * mm->futex_batches must reference a grace period which started after
+	 * mm->futex_phash was assigned. See futex_ref_drop().
+	 */
+	mm->futex_batches = get_state_synchronize_rcu();
 	kvfree_rcu(fph, rcu);
 	return true;
 }

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-30  6:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30  6:13 [PATCH 6.18.y] futex: Fix private hash use-after-free on resize Artem Dinaburg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox