diff options
Diffstat (limited to 'sys/arch/sparc64/sparc64/machdep.c')
-rw-r--r-- | sys/arch/sparc64/sparc64/machdep.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/sys/arch/sparc64/sparc64/machdep.c b/sys/arch/sparc64/sparc64/machdep.c index 5e1a341b10c..b4b34288760 100644 --- a/sys/arch/sparc64/sparc64/machdep.c +++ b/sys/arch/sparc64/sparc64/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.74 2004/11/02 21:20:59 miod Exp $ */ +/* $OpenBSD: machdep.c,v 1.75 2005/03/29 19:34:07 kettenis Exp $ */ /* $NetBSD: machdep.c,v 1.108 2001/07/24 19:30:14 eeh Exp $ */ /*- @@ -102,6 +102,7 @@ #include <sys/sysctl.h> #include <sys/exec_elf.h> +#include <dev/rndvar.h> #ifdef SYSVMSG #include <sys/msg.h> @@ -398,6 +399,28 @@ setregs(p, pack, stack, retval) int pstate = PSTATE_USER; Elf_Ehdr *eh = pack->ep_hdr; + /* + * Setup the process StackGhost cookie which will be XORed into + * the return pointer as register windows are over/underflowed. + */ + p->p_addr->u_pcb.pcb_wcookie = ((u_int64_t)arc4random() << 32) | + arc4random(); + + /* The cookie needs to guarantee invalid alignment after the XOR. */ + switch (p->p_addr->u_pcb.pcb_wcookie % 3) { + case 0: /* Two lsb's already both set except if the cookie is 0. */ + p->p_addr->u_pcb.pcb_wcookie |= 0x3; + break; + case 1: /* Set the lsb. */ + p->p_addr->u_pcb.pcb_wcookie = 1 | + (p->p_addr->u_pcb.pcb_wcookie & ~0x3); + break; + case 2: /* Set the second most lsb. */ + p->p_addr->u_pcb.pcb_wcookie = 2 | + (p->p_addr->u_pcb.pcb_wcookie & ~0x3); + break; + } + /* Don't allow misaligned code by default */ p->p_md.md_flags &= ~MDP_FIXALIGN; |