From a09e6171a624f21d1592a839040fe39696d4f6fc Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 2 Jul 2021 23:30:41 +0200 Subject: [PATCH] Kernel: Don't allow allocate_tls() if the process has multiple threads We can't safely update the other threads' FS selector. This shouldn't be a problem in practice because allocate_tls() is only used by the loader. --- Kernel/Syscalls/mmap.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Kernel/Syscalls/mmap.cpp b/Kernel/Syscalls/mmap.cpp index dd0cc61204..3a44c41b1c 100644 --- a/Kernel/Syscalls/mmap.cpp +++ b/Kernel/Syscalls/mmap.cpp @@ -578,12 +578,18 @@ KResultOr Process::sys$allocate_tls(Userspace initial_data return EFAULT; Thread* main_thread = nullptr; - for_each_thread([&main_thread](auto& thread) { + bool multiple_threads = false; + for_each_thread([&main_thread, &multiple_threads](auto& thread) { + if (main_thread) + multiple_threads = true; main_thread = &thread; return IterationDecision::Break; }); VERIFY(main_thread); + if (multiple_threads) + return EINVAL; + auto range = space().allocate_range({}, size); if (!range.has_value()) return ENOMEM;