[PATCH] futex: sync set the hash table slot

Edward Adam Davis posted 1 patch 8 months, 1 week ago
kernel/futex/core.c | 5 +++++
1 file changed, 5 insertions(+)
[PATCH] futex: sync set the hash table slot
Posted by Edward Adam Davis 8 months, 1 week ago
Prevent different processes from setting the hash table at the same
time to avoid hash table damage.

Reported-by: syzbot+0a5079ee014f4b907817@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=0a5079ee014f4b907817
Tested-by: syzbot+0a5079ee014f4b907817@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
 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