]> Cypherpunks repositories - gostls13.git/commit
cmd/5l, cmd/6l, cmd/8l: fix nacl binary corruption bug
authorRuss Cox <rsc@golang.org>
Thu, 28 Aug 2014 02:53:28 +0000 (22:53 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 28 Aug 2014 02:53:28 +0000 (22:53 -0400)
commita9b2651ade68733405cdc296d66d9b9d8ea68bf0
treef5e6a09145e6caa22a2c3089e764e3a47c477212
parentf9b9ecc5ee1b3ea8212ee801e719fb748dedc20e
cmd/5l, cmd/6l, cmd/8l: fix nacl binary corruption bug

NaCl requires the addition of a 32-byte "halt sled" at the end
of the text segment. This means that segtext.len is actually
32 bytes shorter than reality. The computation of the file offset
of the end of the data segment did not take this 32 bytes into
account, so if len and len+32 rounded up (by 64k) to different
values, the symbol table overwrote the last page of the data
segment.

The last page of the data segment is usually the C .string
symbols, which contain the strings used in error prints
by the runtime. So when this happens, your program
probably crashes, and then when it does, you get binary
garbage instead of all the usual prints.

The chance of hitting this with a randomly sized text segment
is 32 in 65536, or 1 in 2048.

If you add or remove ANY code while trying to debug this
problem, you're overwhelmingly likely to bump the text
segment one way or the other and make the bug disappear.

Correct all the computations to use segdata.fileoff+segdata.filelen
instead of trying to rederive segdata.fileoff.

This fixes the failure during the nacl/amd64p32 build.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/135050043
src/cmd/5l/asm.c
src/cmd/6l/asm.c
src/cmd/8l/asm.c