]> Cypherpunks repositories - gostls13.git/commit
runtime: avoid overflow in markrootBlock
authorIan Lance Taylor <iant@golang.org>
Mon, 16 Sep 2019 19:35:15 +0000 (12:35 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 20 Sep 2019 05:02:16 +0000 (05:02 +0000)
commit66e562cc522ecbb269d2a2d9cffb1bdba2e37aee
treeb3bbb60e385ccef46859673a420a8808e5da9bef
parente2cbb7f629d05807925a5dcd08b61b2a30306ac5
runtime: avoid overflow in markrootBlock

In a position independent executable the data or BSS may be located
close to the end of memory. If it is placed closer than
rootBlockBytes, then the calculations in markrootBlock would overflow,
and the test that ensures that n is not larger than n0 would fail.
This would then cause scanblock to scan data that it shouldn't,
using an effectively random ptrmask, leading to program crashes.

No test because the only way to test it is to build a PIE and convince
the kernel to put the data section near the end of memory, and I don't
know how to do that. Or perhaps we could use a linker script, but that
is painful.

The new code is algebraically identical to the original code, but
avoids the potential overflow of b+rootBlockBytes.

Change-Id: Ieb4e5465174bb762b063d2491caeaa745017345e
Reviewed-on: https://go-review.googlesource.com/c/go/+/195717
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/mgcmark.go