]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: avoid read overrun in heapdump
authorRuss Cox <rsc@golang.org>
Tue, 9 Sep 2014 19:38:55 +0000 (15:38 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 9 Sep 2014 19:38:55 +0000 (15:38 -0400)
Start the stack a few words below the actual top, so that
if something tries to read goexit's caller PC from the stack,
it won't fault on a bad memory address.
Today, heapdump does that.
Maybe tomorrow, traceback or something else will do that.
Make it not a bug.

TBR=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/136450043

src/runtime/proc.c

index a7f9db410f3b5e1d0511aa55dd0a6c45eb68a09d..54efb035bf8503ab89d5dfba2502affca5f6cb85 100644 (file)
@@ -1047,6 +1047,7 @@ runtime·newextram(void)
        gp = runtime·malg(4096);
        gp->sched.pc = (uintptr)runtime·goexit;
        gp->sched.sp = gp->stack.hi;
+       gp->sched.sp -= 4*sizeof(uintreg); // extra space in case of reads slightly beyond frame
        gp->sched.lr = 0;
        gp->sched.g = gp;
        gp->syscallpc = gp->sched.pc;
@@ -2229,6 +2230,7 @@ runtime·newproc1(FuncVal *fn, byte *argp, int32 narg, int32 nret, void *callerp
                runtime·throw("newproc1: new g is not Gdead");
 
        sp = (byte*)newg->stack.hi;
+       sp -= 4*sizeof(uintreg); // extra space in case of reads slightly beyond frame
        sp -= siz;
        runtime·memmove(sp, argp, narg);
        if(thechar == '5') {