Skip to content

Commit

Permalink
runtime: acquire stack lock in traceEvent
Browse files Browse the repository at this point in the history
traceEvent records system call events after a G has already entered
_Gsyscall, which means the garbage collector could be installing stack
barriers in the G's stack during the traceEvent. If traceEvent
attempts to capture the user stack during this, it may observe a
inconsistent stack barriers and panic. Fix this by acquiring the stack
lock around the stack walk in traceEvent.

Fixes golang#14101.

Change-Id: I15f0ab0c70c04c6e182221f65a6f761c5a896459
Reviewed-on: https://go-review.googlesource.com/18973
Run-TryBot: Austin Clements <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Russ Cox <[email protected]>
  • Loading branch information
aclements authored and rsc committed Jan 27, 2016
1 parent eb3b183 commit 08594ac
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/runtime/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,12 @@ func traceEvent(ev byte, skip int, args ...uint64) {
nstk = callers(skip, buf.stk[:])
} else if gp != nil {
gp = mp.curg
nstk = gcallers(gp, skip, buf.stk[:])
// This may happen when tracing a system call,
// so we must lock the stack.
if gcTryLockStackBarriers(gp) {
nstk = gcallers(gp, skip, buf.stk[:])
gcUnlockStackBarriers(gp)
}
}
if nstk > 0 {
nstk-- // skip runtime.goexit
Expand Down

0 comments on commit 08594ac

Please sign in to comment.