From: Jason A. Donenfeld Date: Sun, 28 Feb 2021 11:24:02 +0000 (+0100) Subject: runtime: see whether gp==nil before checking preemption state X-Git-Tag: go1.17beta1~769 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=98dd205fa4f125c8ba8099c3d84d95189666068e;p=gostls13.git runtime: see whether gp==nil before checking preemption state Recent we changed from using gFromTLS to using gFromSP, which apparently sometimes returns nil. This causes crashes when dereferenced. Fix that by not checking for preemption in the case that gFromSP returns nil. Fixes #44679. Change-Id: I0199ebe7cd113379c5fa35c27932d913df79092a Reviewed-on: https://go-review.googlesource.com/c/go/+/297390 Trust: Jason A. Donenfeld Run-TryBot: Jason A. Donenfeld TryBot-Result: Go Bot Reviewed-by: Russ Cox --- diff --git a/src/runtime/os_windows.go b/src/runtime/os_windows.go index 707c9054b5..705b42c61c 100644 --- a/src/runtime/os_windows.go +++ b/src/runtime/os_windows.go @@ -1380,7 +1380,7 @@ func preemptM(mp *m) { // Does it want a preemption and is it safe to preempt? gp := gFromSP(mp, c.sp()) - if wantAsyncPreempt(gp) { + if gp != nil && wantAsyncPreempt(gp) { if ok, newpc := isAsyncSafePoint(gp, c.ip(), c.sp(), c.lr()); ok { // Inject call to asyncPreempt targetPC := funcPC(asyncPreempt)