]> Cypherpunks repositories - gostls13.git/commit
runtime: randomize heap base address
authorRoland Shoemaker <bracewell@google.com>
Wed, 21 May 2025 02:03:44 +0000 (02:03 +0000)
committerRoland Shoemaker <roland@golang.org>
Thu, 24 Jul 2025 16:59:23 +0000 (09:59 -0700)
commit6669aa3b14d98d90929ca860421e5308374b0f46
tree52f29bd6ddecd9e4b8aef63416d2d8f819cbad3c
parent26338a7f691b45017168b6523c95d4578a2cfd4d
runtime: randomize heap base address

During initialization, allow randomizing the heap base address by
generating a random uint64 and using its bits to randomize various
portions of the heap base address.

We use the following method to randomize the base address:

* We first generate a random heapArenaBytes aligned address that we use
  for generating the hints.
* On the first call to mheap.grow, we then generate a random
  PallocChunkBytes aligned offset into the mmap'd heap region, which we
  use as the base for the heap region.
* We then mark a random number of pages within the page allocator as
  allocated.

Our final randomized "heap base address" becomes the first byte of
the first available page returned by the page allocator. This results
in an address with at least heapAddrBits-gc.PageShift-1 bits of
entropy.

Fixes #27583

Change-Id: Ideb4450a5ff747a132f702d563d2a516dec91a88
Reviewed-on: https://go-review.googlesource.com/c/go/+/674835
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/internal/goexperiment/exp_randomizedheapbase64_off.go [new file with mode: 0644]
src/internal/goexperiment/exp_randomizedheapbase64_on.go [new file with mode: 0644]
src/internal/goexperiment/flags.go
src/runtime/export_test.go
src/runtime/malloc.go
src/runtime/mheap.go
src/runtime/mpagealloc.go
src/runtime/proc.go