1
0
mirror of https://github.com/golang/go synced 2024-11-26 23:51:29 -07:00

runtime: fix past-the-end write of wasmStack

On Wasm, at program start, we set the SP to
wasmStack+sizeof(wasmStack), and start to write on it. This write
is actually past the end of wasmStack. This may scribble to some
other variable next to it in the data segment. Or if wasmStack
happens to be the last object in the data segment, we'll scribble
to unreserved memory and cause the next sysReserve return
non-zero memory. Either way, this is bad. Fix this by subtracting
16 before writing.

Found while debugging the new page allocator (CL 190622 and the
stack) with Michael. We found that on Wasm, the first sysReserve
may return memory with the first a few words being non-zero.

Change-Id: I2d76dd3fee85bddb2ff6a902b5876dea3f2969a0
Reviewed-on: https://go-review.googlesource.com/c/go/+/202086
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Cherry Zhang 2019-10-18 22:18:27 -04:00
parent 46aa8354fa
commit e9c994954f

View File

@ -19,7 +19,7 @@ TEXT _rt0_wasm_js(SB),NOSPLIT,$0
// R0: argc (i32) // R0: argc (i32)
// R1: argv (i32) // R1: argv (i32)
TEXT wasm_export_run(SB),NOSPLIT,$0 TEXT wasm_export_run(SB),NOSPLIT,$0
MOVD $runtime·wasmStack+m0Stack__size(SB), SP MOVD $runtime·wasmStack+(m0Stack__size-16)(SB), SP
Get SP Get SP
Get R0 // argc Get R0 // argc