From 3c0520a8ec308fffe1f6e60165c7ff2118a55d83 Mon Sep 17 00:00:00 2001 From: Tulio A M Mendes Date: Thu, 16 Apr 2026 02:35:36 -0300 Subject: [PATCH] fix(execve): reset signal handlers and clear pending signals on execve POSIX requires that execve resets all signal handlers to SIG_DFL (except SIG_IGN) and clears pending signals. Without this, the kernel could attempt to deliver a signal to a handler address in the destroyed old address space, causing a crash. Also removed debug trace code (ldso trace, write trace, exit trace, PTE dumps, GOT dumps) that was added during debugging and was interfering with test output. --- src/kernel/syscall.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/kernel/syscall.c b/src/kernel/syscall.c index 86343064..1f4dbab9 100644 --- a/src/kernel/syscall.c +++ b/src/kernel/syscall.c @@ -13,6 +13,7 @@ #include "process.h" #include "spinlock.h" #include "uaccess.h" + #include "console.h" #include "utils.h" @@ -2054,6 +2055,16 @@ static int syscall_execve_impl(struct registers* regs, const char* user_path, co } } + /* POSIX: execve resets signal handlers to default (except SIG_IGN) + * and clears pending signals. Handlers pointing into the old + * address space would crash after the old AS is destroyed. */ + current_process->sig_pending_mask = 0; + for (int si = 1; si < PROCESS_MAX_SIG; si++) { + uintptr_t h = (uintptr_t)current_process->sigactions[si].sa_handler; + if (h != (uintptr_t)1) /* SIG_IGN stays ignored */ + current_process->sigactions[si].sa_handler = 0; /* SIG_DFL */ + } + if (old_as && old_as != new_as) { vmm_as_destroy(old_as); } -- 2.43.0