summaryrefslogtreecommitdiffstats
path: root/sys/kern/exec_subr.c
diff options
context:
space:
mode:
authormiod <miod@openbsd.org>2015-02-09 11:52:47 +0000
committermiod <miod@openbsd.org>2015-02-09 11:52:47 +0000
commit2bda40dc64ded01f64f2729a3910b84c37f10acb (patch)
tree3b6464215676047198719b1a9a49ead146e64453 /sys/kern/exec_subr.c
parentOups forgot to remove the enums (diff)
downloadwireguard-openbsd-2bda40dc64ded01f64f2729a3910b84c37f10acb.tar.xz
wireguard-openbsd-2bda40dc64ded01f64f2729a3910b84c37f10acb.zip
Change the way stackgap_random is applied. Instead of applying it within the
fixed stack area of the exec'd image, and risking hitting process limits, should we want to increase stackgap_random, the randomness is applied to the stack region in the process' vmspace.
Diffstat (limited to 'sys/kern/exec_subr.c')
-rw-r--r--sys/kern/exec_subr.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/sys/kern/exec_subr.c b/sys/kern/exec_subr.c
index e51b6af910f..1e34ed57b50 100644
--- a/sys/kern/exec_subr.c
+++ b/sys/kern/exec_subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: exec_subr.c,v 1.47 2015/02/06 23:58:12 deraadt Exp $ */
+/* $OpenBSD: exec_subr.c,v 1.48 2015/02/09 11:52:47 miod Exp $ */
/* $NetBSD: exec_subr.c,v 1.9 1994/12/04 03:10:42 mycroft Exp $ */
/*
@@ -330,6 +330,7 @@ vmcmd_randomize(struct proc *p, struct exec_vmcmd *cmd)
int
exec_setup_stack(struct proc *p, struct exec_package *epp)
{
+ vaddr_t sgap;
#ifdef MACHINE_STACK_GROWS_UP
epp->ep_maxsaddr = USRSTACK;
@@ -340,6 +341,14 @@ exec_setup_stack(struct proc *p, struct exec_package *epp)
#endif
epp->ep_ssize = round_page(p->p_rlimit[RLIMIT_STACK].rlim_cur);
+ if (stackgap_random != 0) {
+ sgap = arc4random() & (stackgap_random - 1);
+ sgap = trunc_page(sgap);
+
+ epp->ep_maxsaddr -= sgap;
+ epp->ep_minsaddr -= sgap;
+ }
+
/*
* set up commands for stack. note that this takes *two*, one to
* map the part of the stack which we can access, and one to map