Skip to content

Commit bbd1a1c

Browse files
committed
runtime: make SIGPROF skip stacks that are being copied
sigprof tracebacks the stack across systemstack switches to make profile tracebacks more complete. However, it does this even if the user stack is currently being copied, which means it may be in an inconsistent state that will cause the traceback to panic. One specific way this can happen is during stack shrinking. Some goroutine blocks for STW, then enters gchelper, which then assists with root marking. If that root marking happens to pick the original goroutine and its stack needs to be shrunk, it will begin to copy that stack. During this copy, the stack is generally inconsistent and, in particular, the actual locations of the stack barriers and their recorded locations are temporarily out of sync. If a SIGPROF happens during this inconsistency, it will walk the stack all the way back to the blocked goroutine and panic when it fails to unwind the stack barriers. Fix this by disallowing jumping to the user stack during SIGPROF if that user stack is in the process of being copied. Fixes #12932. Change-Id: I9ef694c2c01e3653e292ce22612418dd3daff1b4 Reviewed-on: https://go-review.googlesource.com/16819 Reviewed-by: Daniel Morsing <[email protected]> Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent b619d55 commit bbd1a1c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/runtime/proc.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2913,7 +2913,14 @@ func sigprof(pc, sp, lr uintptr, gp *g, mp *m) {
29132913
// This is especially important on windows, since all syscalls are cgo calls.
29142914
n = gentraceback(mp.curg.syscallpc, mp.curg.syscallsp, 0, mp.curg, 0, &stk[0], len(stk), nil, nil, 0)
29152915
} else if traceback {
2916-
n = gentraceback(pc, sp, lr, gp, 0, &stk[0], len(stk), nil, nil, _TraceTrap|_TraceJumpStack)
2916+
flags := uint(_TraceTrap | _TraceJumpStack)
2917+
if gp.m.curg != nil && readgstatus(gp.m.curg) == _Gcopystack {
2918+
// We can traceback the system stack, but
2919+
// don't jump to the potentially inconsistent
2920+
// user stack.
2921+
flags &^= _TraceJumpStack
2922+
}
2923+
n = gentraceback(pc, sp, lr, gp, 0, &stk[0], len(stk), nil, nil, flags)
29172924
}
29182925
if !traceback || n <= 0 {
29192926
// Normal traceback is impossible or has failed.

0 commit comments

Comments
 (0)