runtime: guard unexpected return pc gp.m dereference

If stack scanning reaches here while scanning a waiting goroutine, gp.m
will be nil. We are going to crash anyway because the stack is corrupt,
but we still want to reach the print below for context rather than dying
with a SIGSEGV here.

For #64030.

Change-Id: I6a6a636c378669dc45972e1eb8e06401a0fed223
Reviewed-on: https://go-review.googlesource.com/c/go/+/726522
Auto-Submit: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
Michael Pratt
2025-12-03 15:42:03 -05:00
committed by Gopher Robot
parent bfb851c31e
commit d2aad0df60

View File

@@ -456,7 +456,7 @@ func (u *unwinder) next() {
// get everything, so crash loudly.
fail := u.flags&(unwindPrintErrors|unwindSilentErrors) == 0
doPrint := u.flags&unwindSilentErrors == 0
if doPrint && gp.m.incgo && f.funcID == abi.FuncID_sigpanic {
if doPrint && gp.m != nil && gp.m.incgo && f.funcID == abi.FuncID_sigpanic {
// We can inject sigpanic
// calls directly into C code,
// in which case we'll see a C