Module Name:    src
Committed By:   maxv
Date:           Fri Aug 18 10:28:53 UTC 2017

Modified Files:
        src/sys/arch/amd64/conf: kern.ldscript
        src/sys/arch/i386/conf: kern.ldscript kern.ldscript.4MB

Log Message:
Fill the .text padding with 0xcc (int3), in such a way that any jump into
this area will automatically fault. The alignment within the section is
necessary, in order to fill strictly all of the padding (took me a while
to figure this out); but it does not change the kernel size.

Greatly inspired from FreeBSD, but for some reason they decided not to
apply the alignment.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/amd64/conf/kern.ldscript
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/i386/conf/kern.ldscript
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/i386/conf/kern.ldscript.4MB

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/amd64/conf/kern.ldscript
diff -u src/sys/arch/amd64/conf/kern.ldscript:1.23 src/sys/arch/amd64/conf/kern.ldscript:1.24
--- src/sys/arch/amd64/conf/kern.ldscript:1.23	Wed Jun 14 07:45:45 2017
+++ src/sys/arch/amd64/conf/kern.ldscript	Fri Aug 18 10:28:53 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern.ldscript,v 1.23 2017/06/14 07:45:45 maxv Exp $	*/
+/*	$NetBSD: kern.ldscript,v 1.24 2017/08/18 10:28:53 maxv Exp $	*/
 
 #include "assym.h"
 
@@ -13,12 +13,13 @@ __LARGE_PAGE_SIZE = 0x200000 ;
 ENTRY(_start)
 SECTIONS
 {
-	.text :
+	.text : AT (ADDR(.text) & 0x0fffffff)
 	{
 		*(.text)
 		*(.text.*)
 		*(.stub)
-	}
+		. = ALIGN(__LARGE_PAGE_SIZE);
+	} =0xCC
 	_etext = . ;
 	PROVIDE (etext = .) ;
 
@@ -79,11 +80,3 @@ SECTIONS
 	}
 }
 
-SECTIONS
-{
-	.text :
-	AT (ADDR(.text) & 0x0fffffff)
-	{
-		*(.text)
-	} = 0
-}

Index: src/sys/arch/i386/conf/kern.ldscript
diff -u src/sys/arch/i386/conf/kern.ldscript:1.19 src/sys/arch/i386/conf/kern.ldscript:1.20
--- src/sys/arch/i386/conf/kern.ldscript:1.19	Sat May 14 08:19:42 2016
+++ src/sys/arch/i386/conf/kern.ldscript	Fri Aug 18 10:28:53 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern.ldscript,v 1.19 2016/05/14 08:19:42 maxv Exp $	*/
+/*	$NetBSD: kern.ldscript,v 1.20 2017/08/18 10:28:53 maxv Exp $	*/
 
 #include "assym.h"
 
@@ -7,12 +7,13 @@ __PAGE_SIZE = 0x1000 ;
 ENTRY(_start)
 SECTIONS
 {
-	.text :
+	.text : AT (ADDR(.text) & 0x0fffffff)
 	{
 		*(.text)
 		*(.text.*)
 		*(.stub)
-	}
+		. = ALIGN(__PAGE_SIZE);
+	} =0xCC
 	_etext = . ;
 	PROVIDE (etext = .) ;
 
@@ -69,11 +70,3 @@ SECTIONS
 	}
 }
 
-SECTIONS
-{
-	.text :
-	AT (ADDR(.text) & 0x0fffffff)
-	{
-		*(.text)
-	} = 0
-}

Index: src/sys/arch/i386/conf/kern.ldscript.4MB
diff -u src/sys/arch/i386/conf/kern.ldscript.4MB:1.17 src/sys/arch/i386/conf/kern.ldscript.4MB:1.18
--- src/sys/arch/i386/conf/kern.ldscript.4MB:1.17	Mon May 16 07:52:31 2016
+++ src/sys/arch/i386/conf/kern.ldscript.4MB	Fri Aug 18 10:28:53 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern.ldscript.4MB,v 1.17 2016/05/16 07:52:31 maxv Exp $	*/
+/*	$NetBSD: kern.ldscript.4MB,v 1.18 2017/08/18 10:28:53 maxv Exp $	*/
 
 #include "assym.h"
 
@@ -12,12 +12,13 @@ __LARGE_PAGE_SIZE = 0x400000 ;
 ENTRY(_start)
 SECTIONS
 {
-	.text :
+	.text : AT (ADDR(.text) & 0x0fffffff)
 	{
 		*(.text)
 		*(.text.*)
 		*(.stub)
-	}
+		. = ALIGN(__LARGE_PAGE_SIZE);
+	} =0xCC
 	_etext = . ;
 	PROVIDE (etext = .) ;
 
@@ -78,11 +79,3 @@ SECTIONS
 	}
 }
 
-SECTIONS
-{
-	.text :
-	AT (ADDR(.text) & 0x0fffffff)
-	{
-		*(.text)
-	} = 0
-}

Reply via email to