9c48398f49
This patch fixes a rare but serious bug. The Go garbage collector only examines Go stacks. When Go code calls a function that is not written in Go, it first calls syscall.Entersyscall. Entersyscall records the position of the Go stack pointer and saves a copy of all the registers. If the garbage collector runs while the thread is executing the non-Go code, the garbage collector fetches the stack pointer and registers from the saved location. Entersyscall saves the registers using the getcontext function. Unfortunately I didn't consider the possibility that Entersyscall might itself change a register before calling getcontext. This only matters for callee-saved registers, as caller-saved registers would be visible on the saved stack. And it only matters if Entersyscall is compiled to save and modify a callee-saved register before it calls getcontext. And it only matters if a garbage collection occurs while the non-Go code is executing. And it only matters if the only copy of a valid Go pointer happens to be in the callee-saved register when Entersyscall is called. When all those conditions are true, the Go pointer might get collected incorrectly, leading to memory corruption. This patch tries to avoid the problem by splitting Entersyscall into two functions. The first is a simple function that just calls getcontext and then calls the rest of Entersyscall. This should fix the problem, provided the simple Entersyscall function does not itself modify any callee-saved registers before calling getcontext. That seems to be true on the systems I checked. But since the argument to getcontext is an offset from a TLS variable, it won't be true on a system which needs to save callee-saved registers in order to get the address of a TLS variable. I don't know why any system would work that way, but I don't know how to rule it out. I think that on any such system this will have to be implemented in assembler. I can't put the ucontext_t structure on the stack, because this function can not split stacks, and the ucontext_t structure is large enough that it could cause a stack overflow. From-SVN: r208390 |
||
---|---|---|
.. | ||
arch.h | ||
array.h | ||
chan.c | ||
cpuprof.c | ||
defs.h | ||
env_posix.c | ||
getncpu-bsd.c | ||
getncpu-irix.c | ||
getncpu-linux.c | ||
getncpu-none.c | ||
getncpu-solaris.c | ||
go-alloc.h | ||
go-append.c | ||
go-assert-interface.c | ||
go-assert.c | ||
go-assert.h | ||
go-breakpoint.c | ||
go-byte-array-to-string.c | ||
go-caller.c | ||
go-callers.c | ||
go-can-convert-interface.c | ||
go-cdiv.c | ||
go-cgo.c | ||
go-check-interface.c | ||
go-construct-map.c | ||
go-convert-interface.c | ||
go-copy.c | ||
go-defer.c | ||
go-defer.h | ||
go-deferred-recover.c | ||
go-eface-compare.c | ||
go-eface-val-compare.c | ||
go-fieldtrack.c | ||
go-getgoroot.c | ||
go-int-array-to-string.c | ||
go-int-to-string.c | ||
go-interface-compare.c | ||
go-interface-eface-compare.c | ||
go-interface-val-compare.c | ||
go-main.c | ||
go-make-slice.c | ||
go-map-delete.c | ||
go-map-index.c | ||
go-map-len.c | ||
go-map-range.c | ||
go-matherr.c | ||
go-memcmp.c | ||
go-nanotime.c | ||
go-new-map.c | ||
go-new.c | ||
go-nosys.c | ||
go-now.c | ||
go-panic.c | ||
go-panic.h | ||
go-print.c | ||
go-recover.c | ||
go-reflect-call.c | ||
go-reflect-map.c | ||
go-rune.c | ||
go-runtime-error.c | ||
go-setenv.c | ||
go-signal.c | ||
go-strcmp.c | ||
go-string-to-byte-array.c | ||
go-string-to-int-array.c | ||
go-string.h | ||
go-strplus.c | ||
go-strslice.c | ||
go-traceback.c | ||
go-trampoline.c | ||
go-type-complex.c | ||
go-type-eface.c | ||
go-type-error.c | ||
go-type-float.c | ||
go-type-identity.c | ||
go-type-interface.c | ||
go-type-string.c | ||
go-type.h | ||
go-typedesc-equal.c | ||
go-typestring.c | ||
go-unsafe-new.c | ||
go-unsafe-newarray.c | ||
go-unsafe-pointer.c | ||
go-unwind.c | ||
go-varargs.c | ||
goc2c.c | ||
iface.goc | ||
interface.h | ||
lfstack.c | ||
lock_futex.c | ||
lock_sema.c | ||
malloc.goc | ||
malloc.h | ||
map.goc | ||
map.h | ||
mcache.c | ||
mcentral.c | ||
mem_posix_memalign.c | ||
mem.c | ||
mfinal.c | ||
mfixalloc.c | ||
mgc0.c | ||
mgc0.h | ||
mheap.c | ||
mprof.goc | ||
msize.c | ||
netpoll_epoll.c | ||
netpoll_kqueue.c | ||
netpoll_select.c | ||
netpoll_stub.c | ||
netpoll.goc | ||
panic.c | ||
parfor.c | ||
print.c | ||
proc.c | ||
race.h | ||
reflect.goc | ||
rtems-task-variable-add.c | ||
runtime1.goc | ||
runtime.c | ||
runtime.h | ||
sema.goc | ||
signal_unix.c | ||
signal_unix.h | ||
sigqueue.goc | ||
string.goc | ||
thread-linux.c | ||
thread-sema.c | ||
thread.c | ||
time.goc | ||
yield.c |