golang/go

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

Open

#79,062 建立於 2026年4月30日

在 GitHub 查看
 (2 留言) (0 反應) (0 負責人)Go (133,883 star) (19,008 fork)batch import
NeedsInvestigationToolProposalcompiler/runtimehelp wanted

描述

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 https://github.com/golang/go/issues/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.

貢獻者指南