[go] runtime: fix bitmap marking when typ.Size_ == goarch.PtrSize with ASAN enabled

3 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Jun 24, 2026, 9:23:12 AM (3 days ago) Jun 24
to goph...@pubsubhelper.golang.org, 秦龙, golang-co...@googlegroups.com

Gerrit Bot has uploaded the change for review

Commit message

runtime: fix bitmap marking when typ.Size_ == goarch.PtrSize with ASAN enabled

When typ.Size_ equals goarch.PtrSize, the writeHeapBitsSmall function uses
dataSize to calculate the bitmap pointer bits mask. However, with ASAN enabled,
dataSize includes the ASAN redzone, causing the bitmap to incorrectly mark the
redzone region as pointers. This patch subtracts the redzone size before
computing the bitmap mask to ensure only the actual user data region is marked.

Fixes: #80136
Change-Id: I9fc4c276d1fb6d5445bebc6234acd2436b1f4d2f
GitHub-Last-Rev: 03ee347e34f4a5a32b77548515e15a8816ab4209
GitHub-Pull-Request: golang/go#80135

Change diff

diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index 8c5ec38..30a50c7 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -2483,3 +2483,29 @@
return 16 << 7
}
}
+
+// actualSize computes the user allocation size from the total size including redzone.
+// Refer to the implementation of the compiler-rt.
+func actualSize(allocSize uintptr) uintptr {
+ if !asanenabled{
+ return allocSize
+ }
+ switch {
+ case allocSize > (1<<16) - 1024 + 16<<6:
+ return allocSize - 16<<7
+ case allocSize > (1<<15) - 512 + 16<<5:
+ return allocSize - 16<<6
+ case allocSize > (1<<14) - 256 + 16<<4:
+ return allocSize - 16<<5
+ case allocSize > 4096 - 128 + 16<<3:
+ return allocSize - 16<<4
+ case allocSize > 512 - 64 + 16<<2:
+ return allocSize - 16<<3
+ case allocSize > 128 - 32 + 16<<1:
+ return allocSize - 16<<2
+ case allocSize > 64 - 16 + 16<<0:
+ return allocSize - 16<<1
+ default:
+ return allocSize - 16<<0
+ }
+}
\ No newline at end of file
diff --git a/src/runtime/mbitmap.go b/src/runtime/mbitmap.go
index 7c05cd6..9828be7 100644
--- a/src/runtime/mbitmap.go
+++ b/src/runtime/mbitmap.go
@@ -628,9 +628,13 @@
// Create repetitions of the bitmap if we have a small slice backing store.
src := src0
if typ.Size_ == goarch.PtrSize {
- src = (1 << (dataSize / goarch.PtrSize)) - 1
+ size := dataSize
+ if asanenabled {
+ size = actualSize(dataSize)
+ }
+ src = (1 << (size / goarch.PtrSize)) - 1
// This object is all pointers, so scanSize is just dataSize.
- scanSize = dataSize
+ scanSize = size
} else {
// N.B. We rely on dataSize being an exact multiple of the type size.
// The alternative is to be defensive and mask out src to the length
@@ -810,6 +814,9 @@
maxIterBytes := span.elemsize
if header == nil {
maxIterBytes = dataSize
+ if asanenabled && gctyp.Size_ == goarch.PtrSize {
+ maxIterBytes = actualSize(dataSize)
+ }
}
off := alignUp(uintptr(cheaprand())%dataSize, goarch.PtrSize)
size := dataSize - off
@@ -836,6 +843,9 @@
maxIterBytes := span.elemsize
if header == nil {
maxIterBytes = dataSize
+ if asanenabled && gctyp.Size_ == goarch.PtrSize {
+ maxIterBytes = actualSize(dataSize)
+ }
}
bad := false
for i := uintptr(0); i < maxIterBytes; i += goarch.PtrSize {

Change information

Files:
  • M src/runtime/malloc.go
  • M src/runtime/mbitmap.go
Change size: S
Delta: 2 files changed, 38 insertions(+), 2 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I9fc4c276d1fb6d5445bebc6234acd2436b1f4d2f
Gerrit-Change-Number: 793740
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-CC: 秦龙 <qinlo...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Gopher Robot (Gerrit)

unread,
Jun 24, 2026, 9:23:25 AM (3 days ago) Jun 24
to 秦龙, Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gopher Robot added 1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Gopher Robot . unresolved

I spotted some possible problems with your PR:

  1. You have a long 79 character line in the commit message body. Please add line breaks to long lines that should be wrapped. Lines in the commit message body should be wrapped at ~76 characters unless needed for things like URLs or tables. (Note: GitHub might render long lines as soft-wrapped, so double-check in the Gerrit commit message shown above.)
2. Do you have the right bug reference format? For this repo, the format is usually 'Fixes #12345' or 'Updates #12345' at the end of the commit message.

Please address any problems by updating the GitHub PR.

When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above. These findings are based on heuristics; if a finding does not apply, briefly reply here saying so.

To update the commit title or commit message body shown here in Gerrit, you must edit the GitHub PR title and PR description (the first comment) in the GitHub web interface using the 'Edit' button or 'Edit' menu entry there. Note: pushing a new commit to the PR will not automatically update the commit message used by Gerrit.

For more details, see:

(In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I9fc4c276d1fb6d5445bebc6234acd2436b1f4d2f
    Gerrit-Change-Number: 793740
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: 秦龙 <qinlo...@gmail.com>
    Gerrit-Comment-Date: Wed, 24 Jun 2026 13:23:19 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    秦龙 (Gerrit)

    unread,
    Jun 25, 2026, 9:04:14 AM (2 days ago) Jun 25
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Keith Randall, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com
    Attention needed from Ian Lance Taylor, Keith Randall and Martin Möhrmann

    秦龙 voted and added 1 comment

    Votes added by 秦龙

    Code-Review+1

    1 comment

    Patchset-level comments
    Gopher Robot . resolved

    I spotted some possible problems with your PR:

      1. You have a long 79 character line in the commit message body. Please add line breaks to long lines that should be wrapped. Lines in the commit message body should be wrapped at ~76 characters unless needed for things like URLs or tables. (Note: GitHub might render long lines as soft-wrapped, so double-check in the Gerrit commit message shown above.)
    2. Do you have the right bug reference format? For this repo, the format is usually 'Fixes #12345' or 'Updates #12345' at the end of the commit message.

    Please address any problems by updating the GitHub PR.

    When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above. These findings are based on heuristics; if a finding does not apply, briefly reply here saying so.

    To update the commit title or commit message body shown here in Gerrit, you must edit the GitHub PR title and PR description (the first comment) in the GitHub web interface using the 'Edit' button or 'Edit' menu entry there. Note: pushing a new commit to the PR will not automatically update the commit message used by Gerrit.

    For more details, see:

    (In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)

    秦龙

    Done

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Ian Lance Taylor
    • Keith Randall
    • Martin Möhrmann
    Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I9fc4c276d1fb6d5445bebc6234acd2436b1f4d2f
      Gerrit-Change-Number: 793740
      Gerrit-PatchSet: 1
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
      Gerrit-Reviewer: 秦龙 <qinlo...@gmail.com>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-Attention: Keith Randall <k...@golang.org>
      Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
      Gerrit-Comment-Date: Thu, 25 Jun 2026 13:04:04 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Comment-In-Reply-To: Gopher Robot <go...@golang.org>
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy

      Gerrit Bot (Gerrit)

      unread,
      1:18 AM (6 hours ago) 1:18 AM
      to 秦龙, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
      Attention needed from Ian Lance Taylor, Keith Randall, Martin Möhrmann and 秦龙

      Gerrit Bot uploaded new patchset

      Gerrit Bot uploaded patch set #2 to this change.
      Following approvals got outdated and were removed:
      • Code-Review: +1 by 秦龙
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Ian Lance Taylor
      • Keith Randall
      • Martin Möhrmann
      • 秦龙
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newpatchset
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I9fc4c276d1fb6d5445bebc6234acd2436b1f4d2f
      Gerrit-Change-Number: 793740
      Gerrit-PatchSet: 2
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: 秦龙 <qinlo...@gmail.com>
      Gerrit-Attention: Keith Randall <k...@golang.org>
      Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
      Gerrit-Attention: 秦龙 <qinlo...@gmail.com>
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy

      Gerrit Bot (Gerrit)

      unread,
      2:58 AM (4 hours ago) 2:58 AM
      to 秦龙, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
      Attention needed from Ian Lance Taylor, Keith Randall, Martin Möhrmann and 秦龙

      Gerrit Bot uploaded new patchset

      Gerrit Bot uploaded patch set #3 to this change.
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Ian Lance Taylor
      • Keith Randall
      • Martin Möhrmann
      • 秦龙
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newpatchset
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I9fc4c276d1fb6d5445bebc6234acd2436b1f4d2f
      Gerrit-Change-Number: 793740
      Gerrit-PatchSet: 3
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy

      Gopher Robot (Gerrit)

      unread,
      3:15 AM (4 hours ago) 3:15 AM
      to 秦龙, Gerrit Bot, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Keith Randall, Martin Möhrmann, golang-co...@googlegroups.com

      Gopher Robot abandoned this change.

      View Change

      Abandoned GitHub PR golang/go#80135 has been closed.

      Gopher Robot abandoned this change

      Related details

      Attention set is empty
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: abandon
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages