瀏覽代碼

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.
Gunnar Beutner 4 年之前
父節點
當前提交
a09e6171a6
共有 1 個文件被更改,包括 7 次插入1 次删除
  1. 7 1
      Kernel/Syscalls/mmap.cpp

+ 7 - 1
Kernel/Syscalls/mmap.cpp

@@ -578,12 +578,18 @@ KResultOr<FlatPtr> Process::sys$allocate_tls(Userspace<const char*> 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;