]> Cypherpunks repositories - gostls13.git/commit
runtime: fix racy stackForceMove check
authorAustin Clements <austin@google.com>
Fri, 5 Nov 2021 19:58:34 +0000 (15:58 -0400)
committerAustin Clements <austin@google.com>
Fri, 5 Nov 2021 20:59:32 +0000 (20:59 +0000)
commit71559a6ffd26031fe562b461d6472fdddbe617eb
treeaaee4859ed4c5533851d37610e8a6968f75581cc
parent7be227ccd0213dd10d831f87c133bc8ac2cbdc73
runtime: fix racy stackForceMove check

Currently, newstack loads gp.stackguard0 twice to check for different
poison values. The race window between these two checks can lead to
unintentional stack doubling, and ultimately to stack overflows.

Specifically, newstack checks if stackguard0 is stackPreempt first,
then it checks if it's stackForceMove. If stackguard0 is set to
stackForceMove on entry, but changes to stackPreempt between the two
checks, newstack will incorrectly double the stack allocation.

Fix this by loading stackguard0 exactly once and then checking it
against different poison values.

The effect of this is relatively minor because stackForceMove is only
used by a small number of runtime tests. I found this because
mayMorestackMove uses stackForceMove aggressively, which makes this
failure mode much more likely.

Change-Id: I1f8b6a6744e45533580a3f45d7030ec2ec65a5fb
Reviewed-on: https://go-review.googlesource.com/c/go/+/361775
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/runtime/stack.go