[PATCH] futex: sync set the hash table slot
From: Edward Adam Davis
Date: Mon Jun 02 2025 - 00:42:58 EST
Prevent different processes from setting the hash table at the same
time to avoid hash table damage.
Reported-by: syzbot+0a5079ee014f4b907817@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=0a5079ee014f4b907817
Tested-by: syzbot+0a5079ee014f4b907817@xxxxxxxxxxxxxxxxxxxxxxxxx
Signed-off-by: Edward Adam Davis <eadavis@xxxxxx>
---
kernel/futex/core.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/kernel/futex/core.c b/kernel/futex/core.c
index 19a2c65f3d37..818dc082670f 100644
--- a/kernel/futex/core.c
+++ b/kernel/futex/core.c
@@ -1754,7 +1754,12 @@ int futex_hash_prctl(unsigned long arg2, unsigned long arg3, unsigned long arg4)
return -EINVAL;
if (arg4 & FH_FLAG_IMMUTABLE)
flags |= FH_IMMUTABLE;
+
+ static DEFINE_MUTEX(fha_syn);
+
+ mutex_lock(&fha_syn);
ret = futex_hash_allocate(arg3, flags);
+ mutex_unlock(&fha_syn);
break;
case PR_FUTEX_HASH_GET_SLOTS:
--
2.43.0