Skip to content

Commit f265044

Browse files
aclementsbroady
authored andcommitted
[release-branch.go1.5] runtime: check that stack barrier unwind is in sync
Currently the stack barrier stub blindly unwinds the next stack barrier from the G's stack barrier array without checking that it's the right stack barrier. If through some bug the stack barrier array position gets out of sync with where we actually are on the stack, this could return to the wrong PC, which would lead to difficult to debug crashes. To address this, this commit adds a check to the amd64 stack barrier stub that it's unwinding the correct stack barrier. Updates #12238. Change-Id: If824d95191d07e2512dc5dba0d9978cfd9f54e02 Reviewed-on: https://go-review.googlesource.com/13948 Reviewed-by: Russ Cox <[email protected]> Reviewed-on: https://go-review.googlesource.com/14241 Reviewed-by: Austin Clements <[email protected]>
1 parent c0dd201 commit f265044

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/runtime/asm_amd64.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,12 @@ TEXT runtime·stackBarrier(SB),NOSPLIT,$0
346346
MOVQ (g_stkbar+slice_array)(CX), DX
347347
MOVQ g_stkbarPos(CX), BX
348348
IMULQ $stkbar__size, BX // Too big for SIB.
349+
MOVQ stkbar_savedLRPtr(DX)(BX*1), R8
349350
MOVQ stkbar_savedLRVal(DX)(BX*1), BX
351+
// Assert that we're popping the right saved LR.
352+
CMPQ R8, SP
353+
JNE 2(PC)
354+
MOVL $0, 0
350355
// Record that this stack barrier was hit.
351356
ADDQ $1, g_stkbarPos(CX)
352357
// Jump to the original return PC.

0 commit comments

Comments
 (0)