go: runtime: canonical 48-bit address bug in lfstack
What version of Go are you using (go version)?
go version go1.16.2 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
go env Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/ryanh/.cache/go-build" GOENV="/home/ryanh/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/ryanh/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/ryanh/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/lib/go-1.16" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/lib/go-1.16/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.16.2" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1471403295=/tmp/go-build -gno-record-gcc-switches"
What did you do?
If lfstack gets any pointer on amd64 platforms where the top bit is set then an assert is thrown. In most cases this won’t occur since the kernel will consume the top bit of VA, leaving the userspace with 47bits of VA. This is a logic bug around address canonicalization.
Check is here: https://github.com/golang/go/blob/master/src/runtime/lfstack.go#L28 Pointer sign extension is here: https://github.com/golang/go/blob/master/src/runtime/lfstack_64bit.go#L52
I don’t have a basic application or environment for reproducing this. Easy to see the logic bug.
What did you expect to see?
While it is correct that you must canonicalize the pointer by sign extending it on 48bit systems (I’m not even going to bring up LA57). The check inside of lfstack is incorrect since it assumes the sign extension will never occur. Thus assuming it will never receive a true 48-bit pointer. This assumption is broken in environments where you get 48-bit pointers with the high bit set. This is purely a simple logic bug, it shouldn’t assert in this case.
What did you see instead?
An assert on 48-bit address with high bit set.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 44 (21 by maintainers)
Commits related to this issue
- Allocator: Reserve upper 128TB of VA on 64-bit process Only a partial fix for #1330, still needs preemption disabled to work. On x86-64 hosts the Linux kernel resides in the top bit of VA which isn'... — committed to Sonicadvance1/FEX by Sonicadvance1 5 years ago
- runtime: align taggable pointers more so we can use low bits for tag Currently we assume alignment to 8 bytes, so we can steal the low 3 bits. This CL assumes alignment to 512 bytes, so we can steal ... — committed to golang/go by randall77 2 years ago
- runtime: increase freebsd/amd64 pointer size from 48 to 57 bits Because freebsd is now enabling la57 by default. Fixes #49405 Change-Id: I30f7bac8b8a9baa85e0c097e06072c19ad474e5a Reviewed-on: https... — committed to TheRakeshPurohit/go-2 by randall77 2 years ago
- runtime: increase freebsd/amd64 pointer size from 48 to 57 bits Because freebsd is now enabling la57 by default. Fixes #49405 Change-Id: I30f7bac8b8a9baa85e0c097e06072c19ad474e5a Reviewed-on: https... — committed to Sirherobrine23/go by randall77 2 years ago
Ahh ok, well I was pretty optimistic there. It would of course be nice to get this into the ports tree sooner rather than later so we can stop universally limiting pointer width on the builders (with all of its downstream effects).
So, if it’s possible to backport to 1.24, it’d make a difference for us. But we also understand that sometimes dicey is dicey.
Correct, if LA57 is enabled, then mmap(NULL, …) can return addresses above
1 << 47. The main thread stack is also likely to be above1 << 47as well since main thread stacks are typically allocated at the “top” of the user address space.Hi @randall77 On FreeBSD (developer branch), we are noticing this issue on newer CPUs that have the LA57 feature.
Full build log is here: https://people.freebsd.org/~dbaio/go/go121-gohan06-logs.txt
I can run some tests. Just guide me, please.
Details about the CPU:
When building on another box (same FreeBSD version) that doesn’t have LA57, it works just fine.