From 77aac7bb75edc222dd7b350e8b76c20c79da5f43 Mon Sep 17 00:00:00 2001 From: Roland Shoemaker Date: Wed, 17 Sep 2025 21:10:11 +0000 Subject: [PATCH] runtime: don't enable heap randomization if MSAN or ASAN is enabled 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 Reviewed-by: Michael Knyszek Auto-Submit: Roland Shoemaker --- src/runtime/export_test.go | 3 +-- src/runtime/malloc.go | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/runtime/export_test.go b/src/runtime/export_test.go index 99c665c6d0..607281d382 100644 --- a/src/runtime/export_test.go +++ b/src/runtime/export_test.go @@ -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 diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index ec5f0765ba..5b5a633d9a 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -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. -- 2.52.0