]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.3] cmd/5l, cmd/6l, cmd/8l: fix nacl binary corruption bug
authorRuss Cox <rsc@golang.org>
Tue, 30 Sep 2014 16:43:49 +0000 (12:43 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 30 Sep 2014 16:43:49 +0000 (12:43 -0400)
««« CL 135050043 / 57dfd03985a9
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
»»»

LGTM=bradfitz
R=golang-codereviews
CC=adg, bradfitz, golang-codereviews, iant
https://golang.org/cl/151150044

src/cmd/5l/asm.c
src/cmd/6l/asm.c
src/cmd/8l/asm.c

index 5e9267b5ba33d471621a23971cd10c7cb75cfa8f..e879212188c7966c7c58e0e2e5265c21c213985d 100644 (file)
@@ -599,10 +599,10 @@ asmb(void)
                        if(iself)
                                goto ElfSym;
                case Hplan9:
-                       symo = HEADR+segtext.len+segdata.filelen;
+                       symo = segdata.fileoff+segdata.filelen;
                        break;
                ElfSym:
-                       symo = rnd(HEADR+segtext.filelen, INITRND)+rnd(HEADR+segrodata.filelen, INITRND)+segdata.filelen;
+                       symo = segdata.fileoff+segdata.filelen;
                        symo = rnd(symo, INITRND);
                        break;
                }
index e251e32ca906aad3749c41f03e991d06cae3f83d..7828e289227332a6bb14fd3e5327098266b84619 100644 (file)
@@ -689,10 +689,10 @@ asmb(void)
                case Hplan9:
                case Helf:
                        debug['s'] = 1;
-                       symo = HEADR+segtext.len+segdata.filelen;
+                       symo = segdata.fileoff+segdata.filelen;
                        break;
                case Hdarwin:
-                       symo = rnd(HEADR+segtext.len, INITRND)+rnd(segdata.filelen, INITRND)+machlink;
+                       symo = segdata.fileoff+rnd(segdata.filelen, INITRND)+machlink;
                        break;
                case Hlinux:
                case Hfreebsd:
@@ -701,11 +701,11 @@ asmb(void)
                case Hdragonfly:
                case Hsolaris:
                case Hnacl:
-                       symo = rnd(HEADR+segtext.len, INITRND)+rnd(segrodata.len, INITRND)+segdata.filelen;
+                       symo = segdata.fileoff+segdata.filelen;
                        symo = rnd(symo, INITRND);
                        break;
                case Hwindows:
-                       symo = rnd(HEADR+segtext.filelen, PEFILEALIGN)+segdata.filelen;
+                       symo = segdata.fileoff+segdata.filelen;
                        symo = rnd(symo, PEFILEALIGN);
                        break;
                }
index 114a3eb5d76494d2f3211fe32066f6fffa8d41ce..c135dce709ed62eeee47f626f9451007438656ef 100644 (file)
@@ -619,17 +619,17 @@ asmb(void)
                        if(iself)
                                goto Elfsym;
                case Hplan9:
-                       symo = HEADR+segtext.filelen+segdata.filelen;
+                       symo = segdata.fileoff+segdata.filelen;
                        break;
                case Hdarwin:
-                       symo = rnd(HEADR+segtext.filelen, INITRND)+rnd(segdata.filelen, INITRND)+machlink;
+                       symo = segdata.fileoff+rnd(segdata.filelen, INITRND)+machlink;
                        break;
                Elfsym:
-                       symo = rnd(HEADR+segtext.filelen, INITRND)+rnd(HEADR+segrodata.filelen, INITRND)+segdata.filelen;
+                       symo = segdata.fileoff+segdata.filelen;
                        symo = rnd(symo, INITRND);
                        break;
                case Hwindows:
-                       symo = rnd(HEADR+segtext.filelen, PEFILEALIGN)+segdata.filelen;
+                       symo = segdata.fileoff+segdata.filelen;
                        symo = rnd(symo, PEFILEALIGN);
                        break;
                }