Skip to content

Commit

Permalink
fixes golang#32912
Browse files Browse the repository at this point in the history
The crash occurs when go runtime calls a VDSO function (say
__vdso_clock_gettime) and a signal arrives to that thread.
Since VDSO functions temporarily destroy the G register (R10),
Go functions asynchronously executed in that thread (i.e. Go's signal
handler) can try to load data from the destroyed G, which causes
segmentation fault.
  • Loading branch information
nyuichi committed Sep 9, 2019
1 parent 5d04e76 commit 4b53547
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/runtime/signal_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,12 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
if sigfwdgo(sig, info, ctx) {
return
}
g := getg()
c := &sigctxt{info, ctx}
var g *g
if !inVDSOPage(c.sigpc()) {
g = getg()
}
if g == nil {
c := &sigctxt{info, ctx}
if sig == _SIGPROF {
sigprofNonGoPC(c.sigpc())
return
Expand Down Expand Up @@ -347,7 +350,6 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
signalDuringFork(sig)
}

c := &sigctxt{info, ctx}
c.fixsigcode(sig)
sighandler(sig, info, ctx, g)
setg(g)
Expand Down Expand Up @@ -657,8 +659,12 @@ func sigfwdgo(sig uint32, info *siginfo, ctx unsafe.Pointer) bool {
return false
}
// Determine if the signal occurred inside Go code. We test that:
// (1) we were in a goroutine (i.e., m.curg != nil), and
// (2) we weren't in CGO.
// (1) we weren't in VDSO page,
// (2) we were in a goroutine (i.e., m.curg != nil), and
// (3) we weren't in CGO.
if inVDSOPage(c.sigpc()) {
return false
}
g := getg()
if g != nil && g.m != nil && g.m.curg != nil && !g.m.incgo {
return false
Expand Down
1 change: 1 addition & 0 deletions src/runtime/vdso_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ func vdsoauxv(tag, val uintptr) {
}

// vdsoMarker reports whether PC is on the VDSO page.
//go:nosplit
func inVDSOPage(pc uintptr) bool {
for _, k := range vdsoSymbolKeys {
if *k.ptr != 0 {
Expand Down

0 comments on commit 4b53547

Please sign in to comment.