summaryrefslogtreecommitdiffstats
path: root/sys/kern/exec_subr.c
diff options
context:
space:
mode:
authormatthew <matthew@openbsd.org>2012-08-20 23:25:07 +0000
committermatthew <matthew@openbsd.org>2012-08-20 23:25:07 +0000
commit5f7066906156ece39fb432bab1cea4415d608bfc (patch)
treec17c7fb24eb672c57598476e74a77656ffd85203 /sys/kern/exec_subr.c
parentMAX_LINE_SIZE is supposed to define the max length of a SMTP line ... (diff)
downloadwireguard-openbsd-5f7066906156ece39fb432bab1cea4415d608bfc.tar.xz
wireguard-openbsd-5f7066906156ece39fb432bab1cea4415d608bfc.zip
Add support for .openbsd.randomdata sections and PT_OPENBSD_RANDOMIZE
segments to the kernel, ld (2.15), and ld.so. Tested on alpha, amd64, i386, macppc, and sparc64 (thanks naddy, mpi, and okan!). Idea discussed for some time; committing now for further testing. ok deraadt
Diffstat (limited to 'sys/kern/exec_subr.c')
-rw-r--r--sys/kern/exec_subr.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/sys/kern/exec_subr.c b/sys/kern/exec_subr.c
index b712404f3b3..301214722d6 100644
--- a/sys/kern/exec_subr.c
+++ b/sys/kern/exec_subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: exec_subr.c,v 1.29 2011/06/29 12:16:17 tedu Exp $ */
+/* $OpenBSD: exec_subr.c,v 1.30 2012/08/20 23:25:07 matthew Exp $ */
/* $NetBSD: exec_subr.c,v 1.9 1994/12/04 03:10:42 mycroft Exp $ */
/*
@@ -42,6 +42,7 @@
#include <sys/resourcevar.h>
#include <uvm/uvm.h>
+#include <dev/rndvar.h>
#ifdef DEBUG
/*
@@ -289,6 +290,30 @@ vmcmd_map_zero(struct proc *p, struct exec_vmcmd *cmd)
}
/*
+ * vmcmd_randomize():
+ * handle vmcmd which specifies a randomized address space region.
+ */
+
+int
+vmcmd_randomize(struct proc *p, struct exec_vmcmd *cmd)
+{
+ char *buf;
+ int error;
+
+ if (cmd->ev_len == 0)
+ return (0);
+ if (cmd->ev_len > 1024)
+ return (EINVAL);
+
+ buf = malloc(cmd->ev_len, M_TEMP, M_WAITOK);
+ arc4random_buf(buf, cmd->ev_len);
+ error = copyout(buf, (void *)cmd->ev_addr, cmd->ev_len);
+ free(buf, M_TEMP);
+
+ return (error);
+}
+
+/*
* exec_setup_stack(): Set up the stack segment for an a.out
* executable.
*