]> Cypherpunks repositories - gostls13.git/commit
reflect: fix out-of-bounds pointers calling no-result method
authorAustin Clements <austin@google.com>
Tue, 28 Mar 2017 20:03:24 +0000 (16:03 -0400)
committerAustin Clements <austin@google.com>
Wed, 29 Mar 2017 15:28:49 +0000 (15:28 +0000)
commit627798db4e42e4fd3f80a4149cbfafff80b304f3
tree8f185c28c3abcf584f7235a15dc09df02d992f16
parent6e9ec14186cad6058625415abba2744e2bd83ec7
reflect: fix out-of-bounds pointers calling no-result method

reflect.callReflect heap-allocates a stack frame and then constructs
pointers to the arguments and result areas of that frame. However, if
there are no results, the results pointer will point past the end of
the frame allocation. If there are also no arguments, the arguments
pointer will also point past the end of the frame allocation. If the
GC observes either these pointers, it may panic.

Fix this by not constructing these pointers if these areas of the
frame are empty.

This adds a test of calling no-argument/no-result methods via reflect,
since nothing in std did this before. However, it's quite difficult to
demonstrate the actual failure because it depends on both exact
allocation patterns and on GC scanning the goroutine's stack while
inside one of the typedmemmovepartial calls.

I also audited other uses of typedmemmovepartial and
memclrNoHeapPointers in reflect, since these are the most susceptible
to this. These appear to be the only two cases that can construct
out-of-bounds arguments to these functions.

Fixes #19724.

Change-Id: I4b83c596b5625dc4ad0567b1e281bad4faef972b
Reviewed-on: https://go-review.googlesource.com/38736
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/reflect/all_test.go
src/reflect/value.go