mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] futex: Initialize futex_phash_new during fork().
@ 2025-06-23  8:34 Sebastian Andrzej Siewior
  2025-06-23 13:04 ` [tip: locking/urgent] " tip-bot2 for Sebastian Andrzej Siewior
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-06-23  8:34 UTC (permalink / raw)
  To: linux-kernel
  Cc: André Almeida, Calvin Owens, Darren Hart, Davidlohr Bueso,
	Ingo Molnar, Peter Zijlstra, Thomas Gleixner

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().

Reported-by: Calvin Owens <calvin@wbinvd.org>
Closes: https://lore.kernel.org/all/aFBQ8CBKmRzEqIfS@mozart.vkv.me/
Tested-by: Calvin Owens <calvin@wbinvd.org>
Fixes: bd54df5ea7cad ("futex: Allow to resize the private local hash")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 include/linux/futex.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/futex.h b/include/linux/futex.h
index 005b040c4791b..b37193653e6b5 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);
 }
 
-- 
2.50.0

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip: locking/urgent] futex: Initialize futex_phash_new during fork().
  2025-06-23  8:34 [PATCH] futex: Initialize futex_phash_new during fork() Sebastian Andrzej Siewior
@ 2025-06-23 13:04 ` tip-bot2 for Sebastian Andrzej Siewior
  2025-06-23 16:27 ` [PATCH] " André Almeida
  2025-06-23 16:37 ` Davidlohr Bueso
  2 siblings, 0 replies; 4+ messages in thread
From: tip-bot2 for Sebastian Andrzej Siewior @ 2025-06-23 13:04 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Calvin Owens, Sebastian Andrzej Siewior, Peter Zijlstra (Intel),
	x86, linux-kernel

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@linutronix.de>
AuthorDate:    Mon, 23 Jun 2025 10:34:08 +02:00
Committer:     Peter Zijlstra <peterz@infradead.org>
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@mozart.vkv.me/
Fixes: bd54df5ea7cad ("futex: Allow to resize the private local hash")
Reported-by: Calvin Owens <calvin@wbinvd.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Calvin Owens <calvin@wbinvd.org>
Link: https://lkml.kernel.org/r/20250623083408.jTiJiC6_@linutronix.de
---
 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);
 }
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] futex: Initialize futex_phash_new during fork().
  2025-06-23  8:34 [PATCH] futex: Initialize futex_phash_new during fork() Sebastian Andrzej Siewior
  2025-06-23 13:04 ` [tip: locking/urgent] " tip-bot2 for Sebastian Andrzej Siewior
@ 2025-06-23 16:27 ` André Almeida
  2025-06-23 16:37 ` Davidlohr Bueso
  2 siblings, 0 replies; 4+ messages in thread
From: André Almeida @ 2025-06-23 16:27 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior, linux-kernel
  Cc: Calvin Owens, Darren Hart, Davidlohr Bueso, Ingo Molnar,
	Peter Zijlstra, Thomas Gleixner

Em 23/06/2025 05:34, Sebastian Andrzej Siewior escreveu:
> 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().
> 
> Reported-by: Calvin Owens <calvin@wbinvd.org>
> Closes: https://lore.kernel.org/all/aFBQ8CBKmRzEqIfS@mozart.vkv.me/
> Tested-by: Calvin Owens <calvin@wbinvd.org>
> Fixes: bd54df5ea7cad ("futex: Allow to resize the private local hash")
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Reviewed-by: André Almeida <andrealmeid@igalia.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] futex: Initialize futex_phash_new during fork().
  2025-06-23  8:34 [PATCH] futex: Initialize futex_phash_new during fork() Sebastian Andrzej Siewior
  2025-06-23 13:04 ` [tip: locking/urgent] " tip-bot2 for Sebastian Andrzej Siewior
  2025-06-23 16:27 ` [PATCH] " André Almeida
@ 2025-06-23 16:37 ` Davidlohr Bueso
  2 siblings, 0 replies; 4+ messages in thread
From: Davidlohr Bueso @ 2025-06-23 16:37 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-kernel, Andr� Almeida, Calvin Owens,
	Darren Hart, Ingo Molnar, Peter Zijlstra, Thomas Gleixner

On Mon, 23 Jun 2025, Sebastian Andrzej Siewior wrote:

>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().
>
>Reported-by: Calvin Owens <calvin@wbinvd.org>
>Closes: https://lore.kernel.org/all/aFBQ8CBKmRzEqIfS@mozart.vkv.me/
>Tested-by: Calvin Owens <calvin@wbinvd.org>
>Fixes: bd54df5ea7cad ("futex: Allow to resize the private local hash")
>Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-06-23 16:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-23  8:34 [PATCH] futex: Initialize futex_phash_new during fork() Sebastian Andrzej Siewior
2025-06-23 13:04 ` [tip: locking/urgent] " tip-bot2 for Sebastian Andrzej Siewior
2025-06-23 16:27 ` [PATCH] " André Almeida
2025-06-23 16:37 ` Davidlohr Bueso

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

all inboxes | Powered by JetHome®