golang/go

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

開放

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

 (2 則留言) (0 個反應) (0 位負責人)Go (19,008 個分叉)batch import

倉庫指標

星標
 (133,883 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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.

貢獻者指南