1
0
mirror of https://github.com/golang/go synced 2024-11-20 01:14:40 -07:00
go/src
Austin Clements f90b48e0d3 runtime: require the stack barrier lock to traceback cgo and libcalls
Currently, if sigprof determines that the G is in user code (not cgo
or libcall code), it will only traceback the G stack if it can acquire
the stack barrier lock. However, it has no such restriction if the G
is in cgo or libcall code. Because cgo calls count as syscalls, stack
scanning and stack barrier installation can occur during a cgo call,
which means sigprof could attempt to traceback a G in a cgo call while
scanstack is installing stack barriers in that G's stack. As a result,
the following sequence of events can cause the sigprof traceback to
panic with "missed stack barrier":

1. M1: G1 performs a Cgo call (which, on Windows, is any system call,
   which could explain why this is easier to reproduce on Windows).

2. M1: The Cgo call puts G1 into _Gsyscall state.

3. M2: GC starts a scan of G1's stack. It puts G1 in to _Gscansyscall
   and acquires the stack barrier lock.

4. M3: A profiling signal comes in. On Windows this is a global
   (though I don't think this matters), so the runtime stops M1 and
   calls sigprof for G1.

5. M3: sigprof fails to acquire the stack barrier lock (because the
   GC's stack scan holds it).

6. M3: sigprof observes that G1 is in a Cgo call, so it calls
   gentraceback on G1 with its Cgo transition point.

7. M3: gentraceback on G1 grabs the currently empty g.stkbar slice.

8. M2: GC finishes scanning G1's stack and installing stack barriers.

9. M3: gentraceback encounters one of the just-installed stack
   barriers and panics.

This commit fixes this by only allowing cgo tracebacks if sigprof can
acquire the stack barrier lock, just like in the regular user
traceback case.

For good measure, we put the same constraint on libcall tracebacks.
This case is probably already safe because, unlike cgo calls, libcalls
leave the G in _Grunning and prevent reaching a safe point, so
scanstack cannot run during a libcall. However, this also means that
sigprof will always acquire the stack barrier lock without contention,
so there's no cost to adding this constraint to libcall tracebacks.

Fixes #12528. For 1.5.3 (will require some backporting).

Change-Id: Ia5a4b8e3d66b23b02ffcd54c6315c81055c0cec2
Reviewed-on: https://go-review.googlesource.com/18023
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-12-18 17:08:39 +00:00
..
archive archive/tar: document how Reader.Read handles header-only files 2015-12-17 15:48:10 +00:00
bufio bufio: clarify Read docs 2015-12-01 20:05:25 +00:00
builtin
bytes
cmd cmd/vet: add some checks for invalid pointer passing using cgo 2015-12-18 00:31:21 +00:00
compress compress/bzip2/testdata: make Mark.Twain-Tom.Sawyer.txt free 2015-12-02 02:40:38 +00:00
container
crypto crypto/x509: handle CRLDistributionPoints without FullNames 2015-12-17 07:17:28 +00:00
database/sql database/sql: Add DB.SetConnMaxLifetime 2015-12-02 17:38:31 +00:00
debug debug/elf: transparently decompress compressed sections 2015-12-03 20:53:11 +00:00
encoding encoding/pem: make TestFuzz testing/quick safe 2015-12-08 19:27:20 +00:00
errors
expvar
flag
fmt Revert "fmt: check newline in the end of input" 2015-12-11 06:35:20 +00:00
go go/types: add link to tutorial 2015-12-17 23:02:07 +00:00
hash hash/crc32: add noescape tags to assembly functions 2015-11-25 15:01:10 +00:00
html text/template,html/template: correct comment in DefinedTemplates 2015-11-24 21:52:36 +00:00
image
index/suffixarray
internal os,internal/syscall/windows: use ReadFile/MultiByteToWideChar to read from console 2015-12-17 16:23:39 +00:00
io io/ioutil: add examples to functions 2015-11-30 19:47:18 +00:00
log
math math/big: additional Montgomery cleanup 2015-12-16 20:25:29 +00:00
mime mime: fix parsing of empty string attribute value 2015-12-05 20:14:25 +00:00
net net/http: document ResponseWriter and Handler more; add test 2015-12-17 21:21:31 +00:00
os os/signal: document signal handling 2015-12-17 16:59:39 +00:00
path path/filepath: include test number in TestIssue13582 output 2015-12-15 06:43:35 +00:00
reflect reflect: document DeepEqual, fix case of maps with NaN keys 2015-12-11 05:50:05 +00:00
regexp regexp/syntax: fix handling of \Q...\E 2015-12-01 22:45:12 +00:00
runtime runtime: require the stack barrier lock to traceback cgo and libcalls 2015-12-18 17:08:39 +00:00
sort sort: improve average quicksort performance 2015-12-04 20:41:47 +00:00
strconv
strings
sync internal/race: add package 2015-11-26 16:50:31 +00:00
syscall syscall: fix duplicated copyright header in mksysnum_plan9.sh 2015-12-10 20:45:18 +00:00
testing testing: document that T and B are safe for concurrent calls 2015-12-01 22:01:26 +00:00
text text/template,html/template: correct comment in DefinedTemplates 2015-11-24 21:52:36 +00:00
time time: reject invalid day of month in Parse 2015-12-10 19:12:13 +00:00
unicode unicode/utf8: add test for FullRune 2015-12-01 10:39:06 +00:00
unsafe
vendor/golang.org/x/net/http2/hpack net/http: updated bundled copy of x/net/http2 2015-12-16 21:00:35 +00:00
all.bash
all.bat
all.rc
androidtest.bash
bootstrap.bash
buildall.bash
clean.bash
clean.bat
clean.rc
iostest.bash
make.bash src: remove reference to since-deleted dist -s flag 2015-12-17 22:03:56 +00:00
make.bat
Make.dist
make.rc
nacltest.bash
race.bash
race.bat
run.bash
run.bat
run.rc