mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-02 07:28:21 +00:00
signal: fix possible context corruption
This commit is contained in:
@@ -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
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user