]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: don't enable heap randomization if MSAN or ASAN is enabled
authorRoland Shoemaker <bracewell@google.com>
Wed, 17 Sep 2025 21:10:11 +0000 (21:10 +0000)
committerGopher Robot <gobot@golang.org>
Thu, 18 Sep 2025 00:10:14 +0000 (17:10 -0700)
MSAN and ASAN do confusing things to the memory layout, which are likely
to conflict with heap base randomization, so if they are enabled,
ignore randomizedHeapBase64.

We already didn't turn it on when TSAN was enabled.

Change-Id: I41e59dfc33d8bb059c208a9595442571fb31eea3
Reviewed-on: https://go-review.googlesource.com/c/go/+/704856
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Roland Shoemaker <roland@golang.org>

src/runtime/export_test.go
src/runtime/malloc.go

index 99c665c6d007e21bb1d592c007206a3ddcd3bf6f..607281d3820d526b2aa615d5c76f80899bc26061 100644 (file)
@@ -9,7 +9,6 @@ package runtime
 import (
        "internal/abi"
        "internal/goarch"
-       "internal/goexperiment"
        "internal/goos"
        "internal/runtime/atomic"
        "internal/runtime/gc"
@@ -1156,7 +1155,7 @@ func CheckScavengedBitsCleared(mismatches []BitsMismatch) (n int, ok bool) {
                getg().m.mallocing--
        })
 
-       if goexperiment.RandomizedHeapBase64 && len(mismatches) > 0 {
+       if randomizeHeapBase && len(mismatches) > 0 {
                // When goexperiment.RandomizedHeapBase64 is set we use a series of
                // padding pages to generate randomized heap base address which have
                // both the alloc and scav bits set. Because of this we expect exactly
index ec5f0765ba7f22b258627524f0119eb12330d54b..5b5a633d9aee2e3fc33fb258c02f3e6f187e6710 100644 (file)
@@ -349,7 +349,7 @@ const (
 
        // randomizeHeapBase indicates if the heap base address should be randomized.
        // See comment in mallocinit for how the randomization is performed.
-       randomizeHeapBase = goexperiment.RandomizedHeapBase64 && goarch.PtrSize == 8 && !isSbrkPlatform
+       randomizeHeapBase = goexperiment.RandomizedHeapBase64 && goarch.PtrSize == 8 && !isSbrkPlatform && !raceenabled && !msanenabled && !asanenabled
 
        // randHeapBasePrefixMask is used to extract the top byte of the randomized
        // heap base address.