summaryrefslogtreecommitdiffstats
path: root/sys/kern/exec_elf.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_elf.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_elf.c')
-rw-r--r--sys/kern/exec_elf.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/sys/kern/exec_elf.c b/sys/kern/exec_elf.c
index 4e9f314965f..7cfa7d11ea6 100644
--- a/sys/kern/exec_elf.c
+++ b/sys/kern/exec_elf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: exec_elf.c,v 1.86 2012/03/09 13:01:28 ariane Exp $ */
+/* $OpenBSD: exec_elf.c,v 1.87 2012/08/20 23:25:07 matthew Exp $ */
/*
* Copyright (c) 1996 Per Fogelstrom
@@ -130,6 +130,9 @@ extern char *syscallnames[];
*/
#define ELF_MAX_VALID_PHDR 32
+/* Limit on total PT_OPENBSD_RANDOMIZE bytes. */
+#define ELF_RANDOMIZE_LIMIT 1024
+
/*
* This is the basic elf emul. elf_probe_funcs may change to other emuls.
*/
@@ -327,6 +330,7 @@ ELFNAME(load_file)(struct proc *p, char *path, struct exec_package *epp,
Elf_Addr pos = *last;
int file_align;
int loop;
+ size_t randomizequota = ELF_RANDOMIZE_LIMIT;
NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, path, p);
if ((error = namei(&nd)) != 0) {
@@ -469,6 +473,16 @@ ELFNAME(load_file)(struct proc *p, char *path, struct exec_package *epp,
case PT_NOTE:
break;
+ case PT_OPENBSD_RANDOMIZE:
+ if (ph[i].p_memsz > randomizequota) {
+ error = ENOMEM;
+ goto bad1;
+ }
+ randomizequota -= ph[i].p_memsz;
+ NEW_VMCMD(&epp->ep_vmcmds, vmcmd_randomize,
+ ph[i].p_memsz, ph[i].p_vaddr + pos, NULLVP, 0, 0);
+ break;
+
default:
break;
}
@@ -506,6 +520,7 @@ ELFNAME2(exec,makecmds)(struct proc *p, struct exec_package *epp)
char *interp = NULL;
u_long pos = 0, phsize;
u_int8_t os = OOS_NULL;
+ size_t randomizequota = ELF_RANDOMIZE_LIMIT;
if (epp->ep_hdrvalid < sizeof(Elf_Ehdr))
return (ENOEXEC);
@@ -692,6 +707,16 @@ native:
phdr = pp->p_vaddr;
break;
+ case PT_OPENBSD_RANDOMIZE:
+ if (ph[i].p_memsz > randomizequota) {
+ error = ENOMEM;
+ goto bad;
+ }
+ randomizequota -= ph[i].p_memsz;
+ NEW_VMCMD(&epp->ep_vmcmds, vmcmd_randomize,
+ ph[i].p_memsz, ph[i].p_vaddr + exe_base, NULLVP, 0, 0);
+ break;
+
default:
/*
* Not fatal, we don't need to understand everything