]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.24] cmd/compile: do nil check before calling duff functions,...
authorKeith Randall <khr@golang.org>
Thu, 29 May 2025 00:09:05 +0000 (17:09 -0700)
committerCherry Mui <cherryyz@google.com>
Thu, 12 Jun 2025 03:48:50 +0000 (20:48 -0700)
commit5f2cbe1f643f0ce3a314d41d2eca05d2510f3078
treef31480932ba42789409f08324eeef99a248ad911
parent6796ebb2cb66b316a07998cdcd69b1c486b8579e
[release-branch.go1.24] cmd/compile: do nil check before calling duff functions, on arm64 and amd64

On these platforms, we set up a frame pointer record below
the current stack pointer, so when we're in duffcopy or duffzero,
we get a reasonable traceback. See #73753.

But because this frame pointer record is below SP, it is vulnerable.
Anything that adds a new stack frame to the stack might clobber it.
Which actually happens in #73748 on amd64. I have not yet come across
a repro on arm64, but might as well be safe here.

The only real situation this could happen is when duffzero or duffcopy
is passed a nil pointer. So we can just avoid the problem by doing the
nil check outside duffzero/duffcopy. That way we never add a frame
below duffzero/duffcopy. (Most other ways to get a new frame below the
current one, like async preempt or debugger-generated calls, don't
apply to duffzero/duffcopy because they are runtime functions; we're
not allowed to preempt there.)

Longer term, we should stop putting stuff below SP. #73753 will
include that as part of its remit. But that's not for 1.25, so we'll
do the simple thing for 1.25 for this issue.

Fixes #73908

Change-Id: I913c49ee46dcaee8fb439415a4531f7b59d0f612
Reviewed-on: https://go-review.googlesource.com/c/go/+/676916
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@google.com>
(cherry picked from commit dbaa2d3e6525a29defdff16f354881a93974dd2e)
Reviewed-on: https://go-review.googlesource.com/c/go/+/677095
src/cmd/compile/internal/ssa/_gen/AMD64Ops.go
src/cmd/compile/internal/ssa/_gen/ARM64Ops.go
src/cmd/compile/internal/ssa/opGen.go
test/fixedbugs/issue73748a.go [new file with mode: 0644]
test/fixedbugs/issue73748b.go [new file with mode: 0644]