You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The SIGSEGV handler enters pause, which we try to syscall-buffer. That enters the syscallbuf, switching to the syscallbuf's alt stack.
The SIGALRM fires. The kernel determines (via on_sig_stack() in signal.c) that we aren't currently on the sigaltstack, and builds the new sigframe on the sigaltstack --- overwriting the previous SIGSEGV sigframe!
We return from the SIGALRM handler via sigreturn.
When we try to return from the SIGSEGV handler via sigreturn, it reuses the overwritten sigframe and chaos ensures.
It is not obvious what is the best way to fix this.
Probably the simplest thing to do is forcibly set the SS_AUTODISARM flag on calls to sigaltstack(). That flag does exactly what we need here because it's designed to prevent exactly this bug. I guess there is a compatibility risk with SS_AUTODISARM, which probably centers around the case where code longjmp's out of a signal handler. But we already don't support that in rr when a signal interrupts a syscallbuf'ed syscall. So I think we should just do this.
Yes, it would. Thanks for reminding me --- I remembered discussing that approach, but I forgot you actually implemented it. I should take that over and get it landed.
Activity
rocallahan commentedon Feb 6, 2025
This is a gnarly one!
Here's what happens under rr:
pause, which we try to syscall-buffer. That enters the syscallbuf, switching to the syscallbuf's alt stack.on_sig_stack()insignal.c) that we aren't currently on the sigaltstack, and builds the new sigframe on the sigaltstack --- overwriting the previous SIGSEGV sigframe!rocallahan commentedon Feb 6, 2025
It is not obvious what is the best way to fix this.
Probably the simplest thing to do is forcibly set the
SS_AUTODISARMflag on calls tosigaltstack(). That flag does exactly what we need here because it's designed to prevent exactly this bug. I guess there is a compatibility risk withSS_AUTODISARM, which probably centers around the case where code longjmp's out of a signal handler. But we already don't support that in rr when a signal interrupts a syscallbuf'ed syscall. So I think we should just do this.Keno commentedon Feb 6, 2025
I believe #3322 would also address this by moving us out of the syscallbuf before signal delivery.
rocallahan commentedon Feb 6, 2025
Yes, it would. Thanks for reminding me --- I remembered discussing that approach, but I forgot you actually implemented it. I should take that over and get it landed.
Keno commentedon Feb 6, 2025
👍 Please go ahead. It is also still deep on my todo list, but I don't think I can justify spending any time on it anytime soon.