Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys reduce #ifdef mess caused by PaX
details: https://anonhg.NetBSD.org/src/rev/bc88e798d81d
branches: trunk
changeset: 345369:bc88e798d81d
user: christos <christos%NetBSD.org@localhost>
date: Sun May 22 14:26:09 2016 +0000
description:
reduce #ifdef mess caused by PaX
diffstat:
sys/kern/exec_elf.c | 11 ++---------
sys/kern/exec_subr.c | 6 ++----
sys/kern/init_main.c | 8 ++------
sys/kern/kern_exec.c | 14 +++-----------
sys/kern/kern_pax.c | 8 ++++----
sys/sys/pax.h | 18 +++++++++++++++---
sys/uvm/uvm_mmap.c | 6 ++----
7 files changed, 30 insertions(+), 41 deletions(-)
diffs (265 lines):
diff -r 4a0010190c16 -r bc88e798d81d sys/kern/exec_elf.c
--- a/sys/kern/exec_elf.c Sun May 22 10:11:55 2016 +0000
+++ b/sys/kern/exec_elf.c Sun May 22 14:26:09 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_elf.c,v 1.83 2016/05/08 01:28:09 christos Exp $ */
+/* $NetBSD: exec_elf.c,v 1.84 2016/05/22 14:26:09 christos 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.83 2016/05/08 01:28:09 christos Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.84 2016/05/22 14:26:09 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_pax.h"
@@ -124,9 +124,6 @@
if (ph[i].p_type == PT_LOAD && ph[i].p_align > align)
align = ph[i].p_align;
-#ifndef PAX_ASLR
-# define pax_aslr_exec_offset(epp, align) MAX(align, PAGE_SIZE)
-#endif
offset = (Elf_Addr)pax_aslr_exec_offset(epp, align);
offset += epp->ep_vm_minaddr;
@@ -929,13 +926,9 @@
ELF_NOTE_PAX_NAMESZ) == 0) {
uint32_t flags;
memcpy(&flags, ndesc, sizeof(flags));
-#if defined(PAX_MPROTECT) || defined(PAX_SEGVGUARD) || defined(PAX_ASLR)
/* Convert the flags and insert them into
* the exec package. */
pax_setup_elf_flags(epp, flags);
-#else
- (void)flags; /* UNUSED */
-#endif /* PAX_MPROTECT || PAX_SEGVGUARD || PAX_ASLR */
break;
}
BADNOTE("PaX tag");
diff -r 4a0010190c16 -r bc88e798d81d sys/kern/exec_subr.c
--- a/sys/kern/exec_subr.c Sun May 22 10:11:55 2016 +0000
+++ b/sys/kern/exec_subr.c Sun May 22 14:26:09 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_subr.c,v 1.75 2016/05/13 17:33:43 christos Exp $ */
+/* $NetBSD: exec_subr.c,v 1.76 2016/05/22 14:26:09 christos Exp $ */
/*
* Copyright (c) 1993, 1994, 1996 Christopher G. Demetriou
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exec_subr.c,v 1.75 2016/05/13 17:33:43 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exec_subr.c,v 1.76 2016/05/22 14:26:09 christos Exp $");
#include "opt_pax.h"
@@ -394,9 +394,7 @@
DPRINTF(("ep_minsaddr=%#jx max_stack_size=%#jx\n",
(uintmax_t)epp->ep_minsaddr, (uintmax_t)max_stack_size));
-#ifdef PAX_ASLR
pax_aslr_stack(epp, &max_stack_size);
-#endif /* PAX_ASLR */
DPRINTF(("[RLIMIT_STACK].lim_cur=%#jx max_stack_size=%#jx\n",
(uintmax_t)l->l_proc->p_rlimit[RLIMIT_STACK].rlim_cur,
diff -r 4a0010190c16 -r bc88e798d81d sys/kern/init_main.c
--- a/sys/kern/init_main.c Sun May 22 10:11:55 2016 +0000
+++ b/sys/kern/init_main.c Sun May 22 14:26:09 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: init_main.c,v 1.479 2016/03/28 16:45:44 macallan Exp $ */
+/* $NetBSD: init_main.c,v 1.480 2016/05/22 14:26:09 christos Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.479 2016/03/28 16:45:44 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.480 2016/05/22 14:26:09 christos Exp $");
#include "opt_ddb.h"
#include "opt_inet.h"
@@ -198,9 +198,7 @@
#include <sys/syscall.h>
#include <sys/syscallargs.h>
-#if defined(PAX_MPROTECT) || defined(PAX_SEGVGUARD) || defined(PAX_ASLR)
#include <sys/pax.h>
-#endif /* PAX_MPROTECT || PAX_SEGVGUARD || PAX_ASLR */
#include <secmodel/secmodel.h>
@@ -527,9 +525,7 @@
veriexec_init();
#endif /* NVERIEXEC > 0 */
-#if defined(PAX_MPROTECT) || defined(PAX_SEGVGUARD) || defined(PAX_ASLR)
pax_init();
-#endif /* PAX_MPROTECT || PAX_SEGVGUARD || PAX_ASLR */
#ifdef IPSEC
/* Attach network crypto subsystem */
diff -r 4a0010190c16 -r bc88e798d81d sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c Sun May 22 10:11:55 2016 +0000
+++ b/sys/kern/kern_exec.c Sun May 22 14:26:09 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_exec.c,v 1.429 2016/05/11 02:18:27 ozaki-r Exp $ */
+/* $NetBSD: kern_exec.c,v 1.430 2016/05/22 14:26:09 christos Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.429 2016/05/11 02:18:27 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.430 2016/05/22 14:26:09 christos Exp $");
#include "opt_exec.h"
#include "opt_execfmt.h"
@@ -761,12 +761,6 @@
* Calculate the new stack size.
*/
-#ifdef PAX_ASLR
-#define ASLR_GAP(epp) pax_aslr_stack_gap(epp)
-#else
-#define ASLR_GAP(epp) 0
-#endif
-
#ifdef __MACHINE_STACK_GROWS_UP
/*
* copyargs() fills argc/argv/envp from the lower address even on
@@ -782,7 +776,7 @@
data->ed_argslen = calcargs(data, argenvstrlen);
- const size_t len = calcstack(data, ASLR_GAP(epp) + RTLD_GAP);
+ const size_t len = calcstack(data, pax_aslr_stack_gap(epp) + RTLD_GAP);
if (len > epp->ep_ssize) {
/* in effect, compare to initial limit */
@@ -1164,9 +1158,7 @@
vm->vm_maxsaddr = (void *)epp->ep_maxsaddr;
vm->vm_minsaddr = (void *)epp->ep_minsaddr;
-#ifdef PAX_ASLR
pax_aslr_init_vm(l, vm, epp);
-#endif /* PAX_ASLR */
/* Now map address space. */
error = execve_dovmcmds(l, data);
diff -r 4a0010190c16 -r bc88e798d81d sys/kern/kern_pax.c
--- a/sys/kern/kern_pax.c Sun May 22 10:11:55 2016 +0000
+++ b/sys/kern/kern_pax.c Sun May 22 14:26:09 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_pax.c,v 1.48 2016/05/22 01:09:09 christos Exp $ */
+/* $NetBSD: kern_pax.c,v 1.49 2016/05/22 14:26:09 christos 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.48 2016/05/22 01:09:09 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_pax.c,v 1.49 2016/05/22 14:26:09 christos Exp $");
#include "opt_pax.h"
@@ -451,13 +451,13 @@
return true;
}
-bool
+static bool
pax_aslr_epp_active(struct exec_package *epp)
{
return pax_flags_active(epp->ep_pax_flags, P_PAX_ASLR);
}
-bool
+static bool
pax_aslr_active(struct lwp *l)
{
return pax_flags_active(l->l_proc->p_pax, P_PAX_ASLR);
diff -r 4a0010190c16 -r bc88e798d81d sys/sys/pax.h
--- a/sys/sys/pax.h Sun May 22 10:11:55 2016 +0000
+++ b/sys/sys/pax.h Sun May 22 14:26:09 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pax.h,v 1.20 2016/05/08 01:28:09 christos Exp $ */
+/* $NetBSD: pax.h,v 1.21 2016/05/22 14:26:10 christos Exp $ */
/*-
* Copyright (c) 2006 Elad Efrat <elad%NetBSD.org@localhost>
@@ -52,8 +52,14 @@
extern int pax_aslr_debug;
#endif
+#if defined(PAX_MPROTECT) || defined(PAX_SEGVGUARD) || defined(PAX_ASLR)
void pax_init(void);
void pax_setup_elf_flags(struct exec_package *, uint32_t);
+#else
+# define pax_init()
+# define pax_setup_elf_flags(e, flags) __USE(flags)
+#endif
+
void pax_mprotect_adjust(
#ifdef PAX_MPROTECT_DEBUG
const char *, size_t,
@@ -75,12 +81,18 @@
#define PAX_ASLR_DELTA(delta, lsb, len) \
(((delta) & ((1UL << (len)) - 1)) << (lsb))
-bool pax_aslr_epp_active(struct exec_package *);
-bool pax_aslr_active(struct lwp *);
+#ifdef PAX_ASLR
void pax_aslr_init_vm(struct lwp *, struct vmspace *, struct exec_package *);
void pax_aslr_stack(struct exec_package *, u_long *);
uint32_t pax_aslr_stack_gap(struct exec_package *);
vaddr_t pax_aslr_exec_offset(struct exec_package *, vaddr_t);
void pax_aslr_mmap(struct lwp *, vaddr_t *, vaddr_t, int);
+#else
+# define pax_aslr_init_vm(l, v, e)
+# define pax_aslr_stack(e, o)
+# define pax_aslr_stack_gap(e) 0
+# define pax_aslr_exec_offset(e, a) MAX(a, PAGE_SIZE)
+# define pax_aslr_mmap(l, a, b, c)
+#endif
#endif /* !_SYS_PAX_H_ */
diff -r 4a0010190c16 -r bc88e798d81d sys/uvm/uvm_mmap.c
--- a/sys/uvm/uvm_mmap.c Sun May 22 10:11:55 2016 +0000
+++ b/sys/uvm/uvm_mmap.c Sun May 22 14:26:09 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_mmap.c,v 1.156 2016/04/07 12:07:36 christos Exp $ */
+/* $NetBSD: uvm_mmap.c,v 1.157 2016/05/22 14:26:09 christos Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -46,7 +46,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_mmap.c,v 1.156 2016/04/07 12:07:36 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_mmap.c,v 1.157 2016/05/22 14:26:09 christos Exp $");
#include "opt_compat_netbsd.h"
#include "opt_pax.h"
@@ -417,9 +417,7 @@
PAX_MPROTECT_ADJUST(l, &prot, &maxprot);
-#ifdef PAX_ASLR
pax_aslr_mmap(l, &addr, orig_addr, flags);
-#endif /* PAX_ASLR */
/*
* now let kernel internal function uvm_mmap do the work.
Home |
Main Index |
Thread Index |
Old Index