From 1e630fb78a67cceaff3a0c4a1e104c0662316b3e Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Wed, 10 Feb 2021 21:17:30 +0100 Subject: [PATCH] Kernel: Avoid creating unkillable processes Found by fuzz-syscalls. Can be reproduced by running this in the Shell: $ syscall exit_thread This leaves the process in the 'Dying' state but never actually removes it. Therefore, avoid this scenario by pretending to exit the entire process. --- Kernel/Syscalls/thread.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Kernel/Syscalls/thread.cpp b/Kernel/Syscalls/thread.cpp index b5896c2796..fc24d2d731 100644 --- a/Kernel/Syscalls/thread.cpp +++ b/Kernel/Syscalls/thread.cpp @@ -95,6 +95,12 @@ void Process::sys$exit_thread(Userspace exit_value) { REQUIRE_PROMISE(thread); cli(); + + if (this->thread_count() == 1) { + // If this is the last thread, instead kill the process. + this->sys$exit(0); + } + Thread::current()->exit(reinterpret_cast(exit_value.ptr())); ASSERT_NOT_REACHED(); }