From: Austin Clements Date: Wed, 26 Aug 2015 19:06:43 +0000 (-0400) Subject: [release-branch.go1.5] runtime: check that stack barrier unwind is in sync X-Git-Tag: go1.5.1~7 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f265044a489c9e572ffc141ed2d0e95f05d451c9;p=gostls13.git [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 Reviewed-on: https://go-review.googlesource.com/14241 Reviewed-by: Austin Clements --- diff --git a/src/runtime/asm_amd64.s b/src/runtime/asm_amd64.s index 3b4ca4d012..b7bd3dd34f 100644 --- a/src/runtime/asm_amd64.s +++ b/src/runtime/asm_amd64.s @@ -346,7 +346,12 @@ TEXT runtime·stackBarrier(SB),NOSPLIT,$0 MOVQ (g_stkbar+slice_array)(CX), DX MOVQ g_stkbarPos(CX), BX IMULQ $stkbar__size, BX // Too big for SIB. + MOVQ stkbar_savedLRPtr(DX)(BX*1), R8 MOVQ stkbar_savedLRVal(DX)(BX*1), BX + // Assert that we're popping the right saved LR. + CMPQ R8, SP + JNE 2(PC) + MOVL $0, 0 // Record that this stack barrier was hit. ADDQ $1, g_stkbarPos(CX) // Jump to the original return PC.