[go] runtime: pass actual allocation size to special free

1 view
Skip to first unread message

Michael Knyszek (Gerrit)

unread,
Dec 17, 2025, 4:04:29 PM (2 days ago) Dec 17
to Daniel Morsing, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, David Chase, Go LUCI, t hepudds, golang-co...@googlegroups.com

Michael Knyszek submitted the change

Change information

Commit message:
runtime: keep track of secret allocation size

During a naive attempt to test the new runtime/secret package, I tried
wrapping the entire handshake in a secret.Do call. This lead to a panic
because some of the allocator logic had been previously untested.

freeSpecial takes p and size, but they can be misleading. They don't
refer to the pointer and size of the object with the special attached,
but a pointer to the enclosing object and the size of the span element.

The previous code did not take this into account and when passing the
size to memclr would overwrite nearby objects.

Fix by storing the size of the object being cleared inside the special.

Fixes #76865.
Change-Id: Ifae31f1c8d0609a562a37f37c45aec2f369dc6a5
Reviewed-by: Michael Knyszek <mkny...@google.com>
Reviewed-by: David Chase <drc...@google.com>
Files:
  • M src/runtime/malloc.go
  • M src/runtime/malloc_generated.go
  • M src/runtime/malloc_stubs.go
  • M src/runtime/mheap.go
  • M src/runtime/secret.go
  • A src/runtime/secret/alloc_test.go
  • M src/runtime/secret_nosecret.go
Change size: M
Delta: 7 files changed, 147 insertions(+), 89 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +1 by David Chase, +2 by Michael Knyszek
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ifae31f1c8d0609a562a37f37c45aec2f369dc6a5
Gerrit-Change-Number: 730361
Gerrit-PatchSet: 7
Gerrit-Owner: Daniel Morsing <daniel....@gmail.com>
Gerrit-Reviewer: Daniel Morsing <daniel....@gmail.com>
Gerrit-Reviewer: David Chase <drc...@google.com>
Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages