diff options
| author | Carlos Amedee <carlos@golang.org> | 2024-11-04 11:45:05 -0500 |
|---|---|---|
| committer | Michael Knyszek <mknyszek@google.com> | 2024-11-15 20:08:08 +0000 |
| commit | 252e9def65cd6230447fc11046d7f4b176ae2d4b (patch) | |
| tree | 2f574ea22fa37bccf6be4d19c09204c880281310 /src/runtime | |
| parent | 09f9b5e361646ac0e21b4818ddfcf029a78a9e69 (diff) | |
| download | go-252e9def65cd6230447fc11046d7f4b176ae2d4b.tar.xz | |
runtime: validate all calls to SetFinalizer
This change moves the check for a change in the memory management
system to after the SetFinalizer parameters have been validated.
Moving the check ensures that invalid parameters will never pass the
validation checks.
Change-Id: I9f1d3454f891f7b147c0d86b6720297172e08ef9
Reviewed-on: https://go-review.googlesource.com/c/go/+/625035
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/mfinal.go | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/runtime/mfinal.go b/src/runtime/mfinal.go index a926a8ec35..238820fc06 100644 --- a/src/runtime/mfinal.go +++ b/src/runtime/mfinal.go @@ -409,11 +409,6 @@ func blockUntilEmptyFinalizerQueue(timeout int64) bool { // need to use appropriate synchronization, such as mutexes or atomic updates, // to avoid read-write races. func SetFinalizer(obj any, finalizer any) { - if debug.sbrk != 0 { - // debug.sbrk never frees memory, so no finalizers run - // (and we don't have the data structures to record them). - return - } e := efaceOf(&obj) etyp := e._type if etyp == nil { @@ -426,11 +421,15 @@ func SetFinalizer(obj any, finalizer any) { if ot.Elem == nil { throw("nil elem type!") } - if inUserArenaChunk(uintptr(e.data)) { // Arena-allocated objects are not eligible for finalizers. throw("runtime.SetFinalizer: first argument was allocated into an arena") } + if debug.sbrk != 0 { + // debug.sbrk never frees memory, so no finalizers run + // (and we don't have the data structures to record them). + return + } // find the containing object base, span, _ := findObject(uintptr(e.data), 0, 0) |
