Module Name: src
Committed By: maxv
Date: Fri Dec 7 15:47:11 UTC 2018
Modified Files:
src/sys/arch/x86/conf: files.x86
src/sys/arch/x86/x86: pmap.c
Log Message:
Add an option to have a static kernel memory layout. This option is
disabled by default - that is to say, KASLR remains enabled by default.
To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/sys/arch/x86/conf/files.x86
cvs rdiff -u -r1.312 -r1.313 src/sys/arch/x86/x86/pmap.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/x86/conf/files.x86
diff -u src/sys/arch/x86/conf/files.x86:1.103 src/sys/arch/x86/conf/files.x86:1.104
--- src/sys/arch/x86/conf/files.x86:1.103 Mon Jul 16 06:18:31 2018
+++ src/sys/arch/x86/conf/files.x86 Fri Dec 7 15:47:11 2018
@@ -1,4 +1,4 @@
-# $NetBSD: files.x86,v 1.103 2018/07/16 06:18:31 maxv Exp $
+# $NetBSD: files.x86,v 1.104 2018/12/07 15:47:11 maxv Exp $
# options for MP configuration through the MP spec
defflag opt_mpbios.h MPBIOS MPDEBUG MPBIOS_SCANPCI
@@ -17,6 +17,9 @@ defflag opt_pcifixup.h PCI_ADDR_FIXUP PC
# To be able to test for NetBSD/xen in shared files
defflag opt_xen.h DO_NOT_DEFINE
+# Option to have a static kernel memory layout
+defflag opt_kaslr.h NO_X86_ASLR
+
defflag SVS
define cpubus { [apid = -1] }
Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.312 src/sys/arch/x86/x86/pmap.c:1.313
--- src/sys/arch/x86/x86/pmap.c:1.312 Mon Nov 19 20:44:51 2018
+++ src/sys/arch/x86/x86/pmap.c Fri Dec 7 15:47:11 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.312 2018/11/19 20:44:51 maxv Exp $ */
+/* $NetBSD: pmap.c,v 1.313 2018/12/07 15:47:11 maxv Exp $ */
/*
* Copyright (c) 2008, 2010, 2016, 2017 The NetBSD Foundation, Inc.
@@ -130,7 +130,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.312 2018/11/19 20:44:51 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.313 2018/12/07 15:47:11 maxv Exp $");
#include "opt_user_ldt.h"
#include "opt_lockdebug.h"
@@ -138,6 +138,7 @@ __KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.3
#include "opt_xen.h"
#include "opt_svs.h"
#include "opt_kasan.h"
+#include "opt_kaslr.h"
#include <sys/param.h>
#include <sys/systm.h>
@@ -1360,6 +1361,9 @@ slotspace_rand(int type, size_t sz, size
/* Select a hole. */
cpu_earlyrng(&hole, sizeof(hole));
+#ifdef NO_X86_ASLR
+ hole = 0;
+#endif
hole %= nholes;
startsl = holes[hole].start;
endsl = holes[hole].end;
@@ -1367,6 +1371,9 @@ slotspace_rand(int type, size_t sz, size
/* Select an area within the hole. */
cpu_earlyrng(&va, sizeof(va));
+#ifdef NO_X86_ASLR
+ va = 0;
+#endif
winsize = ((endsl - startsl) * NBPD_L4) - sz;
va %= winsize;
va = rounddown(va, align);