Skip to contentSkip to conversation

futex: Initialize futex_phash_new during fork().

PATCH Applied Sebastian Andrzej Siewior 4 participants 4 messages Jun 23, 2025 Futex

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 futex: Initialize futex_phash_new during fork().

During a hash resize operation the new private hash is stored in mm_struct::futex_phash_new if the current hash can not be immediately replaced.

The new hash must not be copied during fork() into the new task. Doing so will lead to a double-free of the memory by the two tasks.

Initialize the mm_struct::futex_phash_new during fork().

Fixes bd54df5ea7cad ("futex: Allow to resize the private local hash")
---
 include/linux/futex.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/futex.h +1 -0
index 005b040c4791b..b37193653e6b5 100644
@@ -89,6 +89,7 @@ void futex_hash_free(struct mm_struct *mm);
 static inline void futex_mm_init(struct mm_struct *mm)
 {
 	RCU_INIT_POINTER(mm->futex_phash, NULL);
+	mm->futex_phash_new = NULL;
 	mutex_init(&mm->futex_hash_lock);
 }
 
Signature · 1 line
2.50.0
#1 lore raw
The following commit has been merged into the locking/urgent branch of tip:

The following commit has been merged into the locking/urgent branch of tip:

Commit-ID:     a24cc6ce1933eade12aa2b9859de0fcd2dac2c06
Gitweb:        https://git.kernel.org/tip/a24cc6ce1933eade12aa2b9859de0fcd2dac2c06
Author:        Sebastian Andrzej Siewior <[email protected]>
AuthorDate:    Mon, 23 Jun 2025 10:34:08 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Mon, 23 Jun 2025 14:50:37 +02:00

futex: Initialize futex_phash_new during fork().

During a hash resize operation the new private hash is stored in mm_struct::futex_phash_new if the current hash can not be immediately replaced.

The new hash must not be copied during fork() into the new task. Doing so will lead to a double-free of the memory by the two tasks.

Initialize the mm_struct::futex_phash_new during fork().

---
 include/linux/futex.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/futex.h +1 -0
index 005b040..b371936 100644
@@ -89,6 +89,7 @@ void futex_hash_free(struct mm_struct *mm);
 static inline void futex_mm_init(struct mm_struct *mm)
 {
 	RCU_INIT_POINTER(mm->futex_phash, NULL);
+	mm->futex_phash_new = NULL;
 	mutex_init(&mm->futex_hash_lock);
 }
 
reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Sebastian Andrzej Siewior

Em 23/06/2025 05:34, Sebastian Andrzej Siewior escreveu:

Quoted 7 lines

During a hash resize operation the new private hash is stored in mm_struct::futex_phash_new if the current hash can not be immediately replaced.

The new hash must not be copied during fork() into the new task. Doing so will lead to a double-free of the memory by the two tasks.

Quoted 7 lines

Initialize the mm_struct::futex_phash_new during fork().

Fixes bd54df5ea7cad ("futex: Allow to resize the private local hash")
reviewer Reviewed-by on v1 1/1
#3 lore raw
In reply to Sebastian Andrzej Siewior
Quoted 7 lines · Sebastian Andrzej Siewior

During a hash resize operation the new private hash is stored in mm_struct::futex_phash_new if the current hash can not be immediately replaced.

The new hash must not be copied during fork() into the new task. Doing so will lead to a double-free of the memory by the two tasks.

Quoted 7 lines

Initialize the mm_struct::futex_phash_new during fork().

Fixes bd54df5ea7cad ("futex: Allow to resize the private local hash")