Skip to contentSkip to conversation

futex: Initialize mm_struct::futex_ref on mm_init()

PATCH In review Sebastian Andrzej Siewior 2 participants 4 messages Aug 30, 2025 – Sep 1, 2025 Futex

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 futex: Initialize mm_struct::futex_ref on mm_init()

mm_struct::futex_ref needs to be set to NULL during mm_init() to ensure that it is not copied during fork(). Reusing the previous pointer can lead to use-after-free which can trigger

| WARNING: kernel/futex/core.c:1604 at futex_ref_rcu+0xe1/0xf0, CPU#2: swapper/2/0

Initialize mm_struct::futex_ref on mm_init().

Fixes 1b708b38414d3 ("futex: Move futex_hash_free() back to __mmput()")
---
 kernel/futex/core.c | 1 +
 1 file changed, 1 insertion(+)
kernel/futex/core.c +1 -0
index fb63c13aa66fc..125804fbb5cb1 100644
@@ -1722,6 +1722,7 @@ int futex_mm_init(struct mm_struct *mm)
 	RCU_INIT_POINTER(mm->futex_phash, NULL);
 	mm->futex_phash_new = NULL;
 	/* futex-ref */
+	mm->futex_ref = NULL;
 	atomic_long_set(&mm->futex_atomic, 0);
 	mm->futex_batches = get_state_synchronize_rcu();
 	return 0;
Signature · 1 line
2.51.0
#1 lore raw
Quoted 9 lines · Sebastian Andrzej Siewior

mm_struct::futex_ref needs to be set to NULL during mm_init() to ensure that it is not copied during fork(). Reusing the previous pointer can lead to use-after-free which can trigger

| WARNING: kernel/futex/core.c:1604 at futex_ref_rcu+0xe1/0xf0, CPU#2: swapper/2/0

Initialize mm_struct::futex_ref on mm_init().

Fixes 1b708b38414d3 ("futex: Move futex_hash_free() back to __mmput()")

So this one is queued in locking/urgent and I guess I can fold this new one into it so that that commit is whole and fixed.

And then leave it in that branch for one more week for some more testing...

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#2 lore raw
Quoted 1 line · Borislav Petkov

And then leave it in that branch for one more week for some more testing...

Ok, boots on one of my machines, fix folded in and force-pushed.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#3 lore raw
Quoted 4 lines · Borislav Petkov
Quoted 1 line · Borislav Petkov

And then leave it in that branch for one more week for some more testing...

Ok, boots on one of my machines, fix folded in and force-pushed.

Thank you.

Quoted 1 line

Thx.

Sebastian