[tip: locking/urgent] futex: Initialize futex_phash_new during fork().
From: tip-bot2 for Sebastian Andrzej Siewior
Date: Mon Jun 23 2025 - 09:05:46 EST
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 <bigeasy@xxxxxxxxxxxxx>
AuthorDate: Mon, 23 Jun 2025 10:34:08 +02:00
Committer: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
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().
Closes: https://lore.kernel.org/all/aFBQ8CBKmRzEqIfS@xxxxxxxxxxxxx/
Fixes: bd54df5ea7cad ("futex: Allow to resize the private local hash")
Reported-by: Calvin Owens <calvin@xxxxxxxxxx>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Tested-by: Calvin Owens <calvin@xxxxxxxxxx>
Link: https://lkml.kernel.org/r/20250623083408.jTiJiC6_@xxxxxxxxxxxxx
---
include/linux/futex.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/linux/futex.h b/include/linux/futex.h
index 005b040..b371936 100644
--- a/include/linux/futex.h
+++ b/include/linux/futex.h
@@ -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);
}