diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2021-02-10 21:17:30 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-13 00:40:31 +0100 |
commit | 1e630fb78a67cceaff3a0c4a1e104c0662316b3e (patch) | |
tree | 6a03fb637161f334c585dd14d5d9f159ce20cbd5 /Kernel/Syscalls/thread.cpp | |
parent | 5963f2084e4ad7f0c07889fd83dfebe1a952c8fb (diff) | |
download | serenity-1e630fb78a67cceaff3a0c4a1e104c0662316b3e.zip |
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.
Diffstat (limited to 'Kernel/Syscalls/thread.cpp')
-rw-r--r-- | Kernel/Syscalls/thread.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
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<void*> 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<void*>(exit_value.ptr())); ASSERT_NOT_REACHED(); } |