From: Russ Cox Date: Tue, 9 Sep 2014 19:38:55 +0000 (-0400) Subject: runtime: avoid read overrun in heapdump X-Git-Tag: go1.4beta1~455 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=16c59acb9790b0d1d17ed45256b95fa60c2e55f1;p=gostls13.git runtime: avoid read overrun in heapdump 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 --- diff --git a/src/runtime/proc.c b/src/runtime/proc.c index a7f9db410f..54efb035bf 100644 --- a/src/runtime/proc.c +++ b/src/runtime/proc.c @@ -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') {