Skip to content

cmd/asm: don't allow writes outside of a function's stack frame #79062

Open

Description

@nsrip-dd

Go version

go1.26.2 linux/amd64

Output of go env in your module/workspace:

n/a

What did you do?

Wrote the following amd64 assembly function:

#include "textflag.h"

TEXT ·clobber(SB),NOSPLIT,$8-0
        MOVQ $42, 8(SP)
        RET

What did you see happen?

It compiles.

What did you expect to see?

I think it shouldn't compile. The function declares an 8 byte stack frame, and that stack write is outside of the declared stack frame. Such a write was the cause of #77250. In that issue, an assembly function overwrote the frame pointer saved at the top of the stack frame, leading to an execution tracer crash when the function returned. The assembler seems to accept any value for the offset of the SP virtual register. I think the same thing might apply to the FP pseudo-register: the function declares the amount of space for arguments and any read outside of that space is probably a bug.

Activity

  1. gabyhelp commented on Apr 30, 2026

    @gabyhelp
  2. added
    ToolProposalIssues describing a requested change to a Go tool or command-line program.
    on Apr 30, 2026
  3. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on May 1, 2026
  4. dmitshur commented on May 6, 2026

    @dmitshur
    Member

    CC @golang/compiler.

    From triage, we think this probably cannot be made to fail to compile, but instead can be a vet check.

  5. added this to the Backlog milestone on May 6, 2026
  6. 123kaze commented on Jul 21, 2026

    @123kaze

    I’d like to investigate implementing this as a vet check, following the triage suggestion. I’ll first look into how SP/FP operands and frame sizes are represented across architectures, and check for potential false positives in existing assembly. Please let me know if there is a preferred analyzer or scope.

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

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolProposalIssues describing a requested change to a Go tool or command-line program.compiler/runtimeIssues related to the Go compiler and/or runtime.help wanted

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions