summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2003-09-02 17:57:13 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2003-09-02 17:57:13 +0000
commit19f0226468354b35e700ee241500e85bd0673028 (patch)
tree1c6d8d0d6c0399fcc9bb34cdf3245b8cf175d4bf /sys
parentdca278092808b64fa28f9aff61e9fa3d687c2f86 (diff)
add a random offset to uvm_map_hint. this has the primary effect of
scattering ld.so and libraries around, although all mmaps will also have some jitter too. better version after some discussion with drahn testing/ok deraadt henning marcm otto pb
Diffstat (limited to 'sys')
-rw-r--r--sys/uvm/uvm_map.c19
-rw-r--r--sys/uvm/uvm_mmap.c4
2 files changed, 17 insertions, 6 deletions
diff --git a/sys/uvm/uvm_map.c b/sys/uvm/uvm_map.c
index 2c6b39d066a..68948b16881 100644
--- a/sys/uvm/uvm_map.c
+++ b/sys/uvm/uvm_map.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uvm_map.c,v 1.60 2003/06/29 17:31:12 avsm Exp $ */
+/* $OpenBSD: uvm_map.c,v 1.61 2003/09/02 17:57:12 tedu Exp $ */
/* $NetBSD: uvm_map.c,v 1.86 2000/11/27 08:40:03 chs Exp $ */
/*
@@ -79,6 +79,8 @@
#include <sys/pool.h>
#include <sys/kernel.h>
+#include <dev/rndvar.h>
+
#ifdef SYSVSHM
#include <sys/shm.h>
#endif
@@ -1078,16 +1080,25 @@ uvm_map_spacefits(vm_map_t map, vaddr_t *phint, vsize_t length,
vaddr_t
uvm_map_hint(struct proc *p, vm_prot_t prot)
{
+ vaddr_t addr;
+
#ifdef __i386__
/*
* If executable skip first two pages, otherwise start
* after data + heap region.
*/
if ((prot & VM_PROT_EXECUTE) &&
- ((vaddr_t)p->p_vmspace->vm_daddr >= I386_MAX_EXE_ADDR))
- return (round_page(PAGE_SIZE*2));
+ ((vaddr_t)p->p_vmspace->vm_daddr >= I386_MAX_EXE_ADDR)) {
+ addr = (PAGE_SIZE*2) +
+ (arc4random() & (I386_MAX_EXE_ADDR / 2 - 1));
+ return (round_page(addr));
+ }
+#endif
+ addr = (vaddr_t)p->p_vmspace->vm_daddr + MAXDSIZ;
+#ifndef __vax__
+ addr += arc4random() & (256 * 1024 * 1024 - 1);
#endif
- return (round_page((vaddr_t)p->p_vmspace->vm_daddr + MAXDSIZ));
+ return (round_page(addr));
}
/*
diff --git a/sys/uvm/uvm_mmap.c b/sys/uvm/uvm_mmap.c
index 2ddb6286b96..523f7e22e90 100644
--- a/sys/uvm/uvm_mmap.c
+++ b/sys/uvm/uvm_mmap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uvm_mmap.c,v 1.52 2003/09/01 18:06:44 henning Exp $ */
+/* $OpenBSD: uvm_mmap.c,v 1.53 2003/09/02 17:57:12 tedu Exp $ */
/* $NetBSD: uvm_mmap.c,v 1.49 2001/02/18 21:19:08 chs Exp $ */
/*
@@ -451,7 +451,7 @@ sys_mmap(p, v, retval)
if (addr == 0)
addr = uvm_map_hint(p, prot);
else if (!(flags & MAP_TRYFIXED) &&
- addr < uvm_map_hint(p, prot))
+ addr < (vaddr_t)p->p_vmspace->vm_daddr)
addr = uvm_map_hint(p, prot);
}