Skip to content

cmd/compile: inconsistent integer arithmetic result on Go 1.22+arm64 with/without -race [1.22 backport] #68230

Closed

Description

@gopherbot

@randall77 requested issue #68227 to be considered for backport to the next 1.22 minor release.

@gopherbot please open backport issue for 1.22.

Activity

  1. added this to the Go1.22.5 milestone on Jun 28, 2024
  2. changed the title [-]Inconsistent integer arithmetic result on Go 1.22+arm64 with/without -race [1.22 backport][/-] [+]cmd/compile: inconsistent integer arithmetic result on Go 1.22+arm64 with/without -race [1.22 backport][/+] on Jun 28, 2024
  3. gopherbot commented on Jun 28, 2024

    @gopherbot
    ContributorAuthor

    Change https://go.dev/cl/595696 mentions this issue: [release-branch.go1.22] cmd/compile: don't elide zero extension on top of signed values

  4. randall77 commented on Jun 28, 2024

    @randall77
    Contributor

    This issue leads to miscompilation in rare cases involving sign/zero extension and register spill/restore paths.

  5. modified the milestones: Go1.22.5, Go1.22.6 on Jul 2, 2024
  6. added
    CherryPickApprovedUsed during the release process for point releases
    and removed
    CherryPickCandidateUsed during the release process for point releases
    on Jul 3, 2024
  7. added a commit that references this issue on Jul 10, 2024
    45f9ded
  8. gopherbot commented on Jul 10, 2024

    @gopherbot
    ContributorAuthor

    Closed by merging 45f9ded to release-branch.go1.22.

  9. RaduBerinde commented on Nov 5, 2024

    @RaduBerinde
    Contributor

    @randall77 is it within the realm of possibility that this issue could lead to a GC crash like the one below? (perhaps in the presence of unsafe code that does non-trivial pointer arithmetic)

    SIGSEGV: segmentation violation
    PC=0x42b81c m=19 sigcode=1 addr=0x20
    
    goroutine 0 gp=0x400c2121c0 m=19 mp=0x400c210008 [idle]:
    runtime.(*mspan).typePointersOfUnchecked(0x40168850e0?, 0x4015086c00?)
      GOROOT/src/runtime/mbitmap_allocheaders.go:202 +0x3c fp=0xffff4f3fccd0 sp=0xffff4f3fccb0 pc=0x42b81c
    runtime.scanobject(0x400c792000, 0x40000dc168)
      GOROOT/src/runtime/mgcmark.go:1441 +0x1c4 fp=0xffff4f3fcd60 sp=0xffff4f3fccd0 pc=0x437fd4
    runtime.gcDrain(0x40000dc168, 0x2)
      GOROOT/src/runtime/mgcmark.go:1242 +0x1d4 fp=0xffff4f3fcdd0 sp=0xffff4f3fcd60 pc=0x437774
    runtime.gcDrainMarkWorkerDedicated(...)
      GOROOT/src/runtime/mgcmark.go:1124
    runtime.gcBgMarkWorker.func2()
      GOROOT/src/runtime/mgc.go:1402 +0x154 fp=0xffff4f3fce20 sp=0xffff4f3fcdd0 pc=0x433a34
    runtime.systemstack(0x0)
      src/runtime/asm_arm64.s:243 +0x6c fp=0xffff4f3fce30 sp=0xffff4f3fce20 pc=0x48c3fc
    

    (this is from cockroachdb/cockroach#134020)

  10. randall77 commented on Nov 5, 2024

    @randall77
    Contributor

    I guess it is possible, but not terribly likely.

    That fault is because the runtime's internal data is corrupted. For that to happen, we'd have to use the bug to calculate a bad offset during some unsafe.Pointer arithmetic. The bug only causes errors in the high 32 bits, so the bad address would be off by a multiple of 4GB. I guess if your heap is that big, it's possible. For smaller heaps I don't see how you could corrupt the heap using this bug.

  11. RaduBerinde commented on Nov 5, 2024

    @RaduBerinde
    Contributor

    The high 32 bit error could apply to an intermediary result, which then causes us to get an incorrect pointer that is less than 4GB away no? For example things like (x * largeConstant) >> 32 are sometimes used as hash functions.

  12. randall77 commented on Nov 5, 2024

    @randall77
    Contributor

    The high 32 bit error could apply to an intermediary result, which then causes us to get an incorrect pointer that is less than 4GB away no?

    Sure, it is possible.

    For example things like (x * largeConstant) >> 32 are sometimes used as hash functions.

    That particular case seems unlikely to be the problem, as a hash function would certainly be followed by a bounds check or mask. It might cause a hash miss where there should be a hit, but that shouldn't corrupt runtime state.

  13. locked and limited conversation to collaborators on Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CherryPickApprovedUsed during the release process for point releasesFrozenDueToAgecompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions