From fcdd7aa99099976f9e83ff0339a37db82a849806 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Tue, 31 Aug 2021 18:57:42 -0600 Subject: [PATCH] Kernel: Only unlock Mutex once in execve when PT_TRACE_ME is enabled Fixes a regression introduced in 70518e6. Fixes #9704. --- Kernel/Syscalls/execve.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index 4002e0d279..a8b8f7e7a5 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -628,8 +628,11 @@ KResult Process::do_exec(NonnullRefPtr main_program_description // Make sure we release the ptrace lock here or the tracer will block forever. ptrace_locker.unlock(); Thread::current()->send_urgent_signal_to_self(SIGSTOP); + } else { + // Unlock regardless before disabling interrupts. + // Ensure we always unlock after checking ptrace status to avoid TOCTOU ptrace issues + ptrace_locker.unlock(); } - ptrace_locker.unlock(); // unlock before disabling interrupts as well // We enter a critical section here because we don't want to get interrupted between do_exec() // and Processor::assume_context() or the next context switch.