Repository navigation
Closed
Labels
BugReportIssues describing a possible bug in the Go implementation.Issues describing a possible bug in the Go implementation.FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-Windowsarch-amd64compiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Description
Go version
go version go1.24.2 windows/amd64
Output of go env in your module/workspace:
set AR=ar
set CC=gcc
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_ENABLED=0
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set CXX=g++
set GCCGO=gccgo
set GO111MODULE=
set GOAMD64=v1
set GOARCH=amd64
set GOAUTH=netrc
set GOBIN=
set GOCACHE=C:\Users\adreed\AppData\Local\go-build
set GOCACHEPROG=
set GODEBUG=
set GOENV=C:\Users\adreed\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFIPS140=off
set GOFLAGS=
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\adreed\AppData\Local\Temp\go-build3436564709=/tmp/go-build -gno-record-gcc-switches
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMOD=NUL
set GOMODCACHE=C:\Users\adreed\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\adreed\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\adreed\AppData\Roaming\go\telemetry
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.24.2
set GOWORK=
set PKG_CONFIG=pkg-configWhat did you do?
Build a go executable (for instance, AzCopy) and fire it into binskim analyze
What did you see happen?
In attempts to resolve this by setting --buildmode=pie (which I acknowledge is a default, but, figured I'd do a little science anyway)
C:\Users\adreed\Downloads\azcopy.exe: error BA2001: 'azcopy-pie.exe' is a 64-bit image with a preferred base address below the 4GB boundary.
Having a preferred base address below this boundary triggers a compatibility mode in Address Space Layout Randomization (ASLR) on recent versions of Windows that reduces the number of locations to which ASLR may relocate the binary. This reduces the effectiveness of ASLR at mitigating memory corruption vulnerabilities.
To resolve this issue, either use the default preferred base address by removing any uses of /baseaddress from compiler command lines, or /BASE from linker command lines (recommended), or configure your program to start at a base address above 4GB when compiled for 64 bit platforms (by changing the constant passed to /baseaddress or /BASE).
Note that if you choose to continue using a custom preferred base address, you will need to make this modification only for 64-bit builds, as base addresses above 4GB are not valid for 32-bit binaries.
For VC projects make sure that ItemDefinitionGroup - Link - BaseAddress property is not set.
What did you expect to see?
Ideally, we'd be able to either move the base address or remove the preferred base address entirely to address this.
Metadata
Metadata
Assignees
Labels
BugReportIssues describing a possible bug in the Go implementation.Issues describing a possible bug in the Go implementation.FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-Windowsarch-amd64compiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Type
Projects
- StatusShow more project fieldsDone
Activity
adreed-msft commentedon Apr 30, 2025
For reference, this comes to us over in AzCopy land via Azure/azure-storage-azcopy#3012
[-]cmd/go: Preferred base address below the 4GB boundary[/-][+]cmd/comple: preferred base address below the 4GB boundary[/+][-]cmd/comple: preferred base address below the 4GB boundary[/-][+]cmd/compile: preferred base address below the 4GB boundary[/+]adonovan commentedon May 1, 2025
A Go process's text section is already mapped to an unpredictable address, so I'm not sure there's actually a problem to be fixed here. (IIRC, the heap base offset is constant, but heap allocation is likely to be less predictable in general.)
[-]cmd/compile: preferred base address below the 4GB boundary[/-][+]cmd/compile: `-buildmode=pie` should specify a random base address above 32bits to avoid 32 bits compatibility ASLR detections[/+][-]cmd/compile: `-buildmode=pie` should specify a random base address above 32bits to avoid 32 bits compatibility ASLR detections[/-][+]cmd/compile: `-buildmode=pie` should specify a random base address above 32bits to avoid using 32bits compatibility ASLR mode[/+]gabyhelp commentedon May 1, 2025
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
adreed-msft commentedon May 6, 2025
I will turn around and file this as a bug against binskim; I'm curious to see what their view on this is.
adreed-msft commentedon May 6, 2025
microsoft/binskim#1072
prattmic commentedon May 7, 2025
cc @qmuntal
qmuntal commentedon May 9, 2025
BinSkim reports the issue correctly. Go binaries support ASLR, but the Go internal linker sets the preferred base address to 4MB rather than 4GB on windows/amd64, which triggers the undesired ASLR compatibility mode mentioned in the BinSkim report. This is the offending code:
go/src/cmd/link/internal/ld/pe.go
Lines 1100 to 1106 in 49d6777
Note that windows/arm64 do get a 4GB preferred base address.
There is a comment made by @rsc in that code saying that there is a cgo issue that doesn't allow us to increase the limit. More investigation is needed.
gopherbot commentedon May 9, 2025
Change https://go.dev/cl/671515 mentions this issue:
cmd/link: use a 4GB base address for 64-bit PE binariesqmuntal commentedon May 9, 2025
Looks like the Go linker still can't handle 4GB relocations: https://ci.chromium.org/ui/p/golang/builders/try/gotip-windows-amd64/b8715335171107040657/overview. That will need to be fixed.
cmd/link: use >4GB base address for 64-bit PE binaries