Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern obey the executable's ELF alignment constraints for...
details: https://anonhg.NetBSD.org/src/rev/7d959bd82473
branches: trunk
changeset: 351569:7d959bd82473
user: chs <chs%NetBSD.org@localhost>
date: Sat Feb 18 01:29:09 2017 +0000
description:
obey the executable's ELF alignment constraints for PIE.
this fixes gdb of PIE binaries on mac68k (and other platforms
which use an ELF alignment that is larger than PAGE_SIZE).
diffstat:
sys/kern/exec_elf.c | 8 +++++---
sys/kern/kern_pax.c | 13 +++++++------
2 files changed, 12 insertions(+), 9 deletions(-)
diffs (78 lines):
diff -r cab7d7720d0f -r 7d959bd82473 sys/kern/exec_elf.c
--- a/sys/kern/exec_elf.c Sat Feb 18 00:26:16 2017 +0000
+++ b/sys/kern/exec_elf.c Sat Feb 18 01:29:09 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_elf.c,v 1.88 2017/02/12 21:52:46 uwe Exp $ */
+/* $NetBSD: exec_elf.c,v 1.89 2017/02/18 01:29:09 chs Exp $ */
/*-
* Copyright (c) 1994, 2000, 2005, 2015 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.88 2017/02/12 21:52:46 uwe Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.89 2017/02/18 01:29:09 chs Exp $");
#ifdef _KERNEL_OPT
#include "opt_pax.h"
@@ -134,7 +134,9 @@
align = ph[i].p_align;
offset = (Elf_Addr)pax_aslr_exec_offset(epp, align);
- offset += epp->ep_vm_minaddr;
+ if (offset < epp->ep_vm_minaddr)
+ offset = roundup(epp->ep_vm_minaddr, align);
+ KASSERT((offset & (align - 1)) == 0);
for (i = 0; i < eh->e_phnum; i++)
ph[i].p_vaddr += offset;
diff -r cab7d7720d0f -r 7d959bd82473 sys/kern/kern_pax.c
--- a/sys/kern/kern_pax.c Sat Feb 18 00:26:16 2017 +0000
+++ b/sys/kern/kern_pax.c Sat Feb 18 01:29:09 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_pax.c,v 1.57 2016/09/17 02:29:11 christos Exp $ */
+/* $NetBSD: kern_pax.c,v 1.58 2017/02/18 01:29:09 chs Exp $ */
/*
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_pax.c,v 1.57 2016/09/17 02:29:11 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_pax.c,v 1.58 2017/02/18 01:29:09 chs Exp $");
#include "opt_pax.h"
@@ -578,7 +578,7 @@
uint32_t rand;
vaddr_t offset;
- pax_align = align == 0 ? PGSHIFT : align;
+ pax_align = align == 0 ? PAGE_SIZE : align;
l2 = ilog2(pax_align);
rand = cprng_fast32();
@@ -590,7 +590,8 @@
#define PAX_TRUNC(a, b) ((a) & ~((b) - 1))
delta = PAX_ASLR_DELTA(rand, l2, PAX_ASLR_DELTA_EXEC_LEN);
- offset = PAX_TRUNC(delta, pax_align) + PAGE_SIZE;
+ offset = PAX_TRUNC(delta, pax_align);
+ offset = MAX(offset, pax_align);
PAX_DPRINTF("rand=%#x l2=%#zx pax_align=%#zx delta=%#zx offset=%#jx",
rand, l2, pax_align, delta, (uintmax_t)offset);
@@ -608,9 +609,9 @@
if (pax_aslr_flags & PAX_ASLR_EXEC_OFFSET)
goto out;
#endif
- return pax_aslr_offset(align) + PAGE_SIZE;
+ return pax_aslr_offset(align);
out:
- return MAX(align, PAGE_SIZE);
+ return 0;
}
voff_t
Home |
Main Index |
Thread Index |
Old Index