signal: fix possible context corruption

This commit is contained in:
Matheus
2026-06-30 17:37:23 -03:00
parent 99701d2fb9
commit 7c19244208
2 changed files with 13 additions and 7 deletions
+2
View File
@@ -112,6 +112,8 @@ int poll_dowait(polldesc_t *desc, size_t ustimeout) {
__assert(ret || spinlock_try(&desc->lock) == false); __assert(ret || spinlock_try(&desc->lock) == false);
if (ret == SCHED_WAKEUP_REASON_INTERRUPTED) { if (ret == SCHED_WAKEUP_REASON_INTERRUPTED) {
// future note: if this deadlocks, check the caller to see if
// desc is not being reset
spinlock_acquire(&desc->wakeuplock); spinlock_acquire(&desc->wakeuplock);
ret = EINTR; ret = EINTR;
} }
+11 -7
View File
@@ -594,13 +594,16 @@ bool signal_check(struct thread_t *thread, context_t *context, bool syscall, uin
SIGNAL_SETON(&thread->signals.mask, i); SIGNAL_SETON(&thread->signals.mask, i);
} }
// configure return context // do not sync the context until after the usercopy.
memset(context, 0, sizeof(context_t)); // context may point at thread->context, which a page
CTX_INIT(context, true, true); // fault may overwrite for sleeping.
CTX_IP(context) = (uint64_t)action->address; context_t handler_context;
CTX_SP(context) = (uint64_t)stack; memset(&handler_context, 0, sizeof(context_t));
CTX_ARG0(context) = signal; CTX_INIT(&handler_context, true, true);
set_siginfo_ucontext(context, stack); CTX_IP(&handler_context) = (uint64_t)action->address;
CTX_SP(&handler_context) = (uint64_t)stack;
CTX_ARG0(&handler_context) = signal;
set_siginfo_ucontext(&handler_context, stack);
// reset handler if asked for // reset handler if asked for
if (action->flags & SA_RESETHAND) if (action->flags & SA_RESETHAND)
@@ -619,6 +622,7 @@ bool signal_check(struct thread_t *thread, context_t *context, bool syscall, uin
proc_terminate(SIGSEGV); proc_terminate(SIGSEGV);
} }
*context = handler_context;
return retry; return retry;
} }