runtime: crash on SI_USER SigPanic signal

Clean up the code a little bit to make it clearer:

Don't check throwsplit for a SI_USER signal.

If throwsplit is set for a SigPanic signal, always throw;
discard any other flags.

Fixes #36420

Change-Id: Ic9dcd1108603d241f71c040504dfdc6e528f9767
Reviewed-on: https://go-review.googlesource.com/c/go/+/228900
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
Ian Lance Taylor 2020-04-18 20:11:46 -07:00
parent 5a75f7c0b0
commit e5bd6e1c79
4 changed files with 96 additions and 3 deletions

View file

@ -546,10 +546,10 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
if sig < uint32(len(sigtable)) {
flags = sigtable[sig].flags
}
if flags&_SigPanic != 0 && gp.throwsplit {
if c.sigcode() != _SI_USER && flags&_SigPanic != 0 && gp.throwsplit {
// We can't safely sigpanic because it may grow the
// stack. Abort in the signal handler instead.
flags = (flags &^ _SigPanic) | _SigThrow
flags = _SigThrow
}
if isAbortPC(c.sigpc()) {
// On many architectures, the abort function just
@ -588,7 +588,11 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
dieFromSignal(sig)
}
if flags&_SigThrow == 0 {
// _SigThrow means that we should exit now.
// If we get here with _SigPanic, it means that the signal
// was sent to us by a program (c.sigcode() == _SI_USER);
// in that case, if we didn't handle it in sigsend, we exit now.
if flags&(_SigThrow|_SigPanic) == 0 {
return
}