Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: finalizer call has wrong frame size #51457

Closed
cherrymui opened this issue Mar 3, 2022 · 5 comments
Closed

runtime: finalizer call has wrong frame size #51457

cherrymui opened this issue Mar 3, 2022 · 5 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@cherrymui
Copy link
Member

What version of Go are you using (go version)?

tip (bcb89fc)

Does this issue reproduce with the latest release?

Yes. Reproduce with Go 1.17 and tip, not with Go 1.16.

What operating system and processor architecture are you using (go env)?

darwin/amd64

What did you do?

package main

import "runtime"

var ch = make(chan int, 2)

func main() {
	x, y := new([4]int64), new([4]int64) // not tinyalloc'd
	runtime.SetFinalizer(x, F)
	runtime.SetFinalizer(y, F)

	runtime.GC()
	runtime.GC()
	<- ch
	<- ch // make sure it tries to run the second finalizer, therefore the first reflectcall must finish
}

func F(p interface{}) [4]int64 { // 32-byte on-stack result, use up space for call32
	forceSpill()
	ch <- 1
	x := p.(*[4]int64)
	return *x
}

//go:noinline
func forceSpill() {}

This program runs fine with Go 1.16, but crash with Go 1.17 and tip. It is due to finalizer call has wrong frame size on register-ABI platforms, which leads to memory corruption.

Fixed by CL https://go-review.googlesource.com/c/go/+/389574 .

Open an issue for Go 1.18.

@cherrymui cherrymui added this to the Go1.18 milestone Mar 3, 2022
@cherrymui cherrymui added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 3, 2022
@cherrymui
Copy link
Member Author

@gopherbot please backport this to Go 1.17 release. Thanks.

@gopherbot
Copy link

Change https://go.dev/cl/388995 mentions this issue: [release-branch.go1.18] runtime: count spill slot for frame size at finalizer call

@gopherbot
Copy link

Backport issue(s) opened: #51458 (for 1.17).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@gopherbot
Copy link

Change https://go.dev/cl/389794 mentions this issue: [release-branch.go1.17] runtime: count spill slot for frame size at finalizer call

@gopherbot
Copy link

Closed by merging ce427cf to release-branch.go1.18.

gopherbot pushed a commit that referenced this issue Mar 7, 2022
…inalizer call

The finalizer is called using reflectcall. When register ABI is
used, the finalizer's argument is passed in register(s). But the
frame size calculation does not include the spill slot. When the
argument actually spills, it may clobber the caller's stack frame.
This CL fixes it.

Fixes #51457.

Change-Id: Ibcc7507c518ba65c1c5a7759e5cab0ae3fc7efce
Reviewed-on: https://go-review.googlesource.com/c/go/+/389574
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
(cherry picked from commit 58804ea)
Reviewed-on: https://go-review.googlesource.com/c/go/+/388995
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
gopherbot pushed a commit that referenced this issue Mar 14, 2022
…inalizer call

The finalizer is called using reflectcall. When register ABI is
used, the finalizer's argument is passed in register(s). But the
frame size calculation does not include the spill slot. When the
argument actually spills, it may clobber the caller's stack frame.
This CL fixes it.

Updates #51457.
Fixes #51458.

Change-Id: Ibcc7507c518ba65c1c5a7759e5cab0ae3fc7efce
Reviewed-on: https://go-review.googlesource.com/c/go/+/389574
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
(cherry picked from commit 58804ea)
Reviewed-on: https://go-review.googlesource.com/c/go/+/389794
@golang golang locked and limited conversation to collaborators Mar 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

2 participants