Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/aarch64 set kernel text/rodata readonly when not de...
details: https://anonhg.NetBSD.org/src/rev/8673205d2861
branches: trunk
changeset: 991877:8673205d2861
user: ryo <ryo%NetBSD.org@localhost>
date: Fri Aug 03 16:32:55 2018 +0000
description:
set kernel text/rodata readonly when not defined DDB.
set readonly segment on 2Mbytes aligned. (kernel image is mapped with 2Mbytes L2 block)
diffstat:
sys/arch/aarch64/aarch64/genassym.cf | 4 ++-
sys/arch/aarch64/aarch64/locore.S | 41 +++++++++++++++++++++++++++++++++--
sys/arch/aarch64/conf/kern.ldscript | 10 ++++++--
3 files changed, 48 insertions(+), 7 deletions(-)
diffs (106 lines):
diff -r d117b972ffff -r 8673205d2861 sys/arch/aarch64/aarch64/genassym.cf
--- a/sys/arch/aarch64/aarch64/genassym.cf Fri Aug 03 16:31:04 2018 +0000
+++ b/sys/arch/aarch64/aarch64/genassym.cf Fri Aug 03 16:32:55 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: genassym.cf,v 1.5 2018/07/17 10:01:59 ryo Exp $
+# $NetBSD: genassym.cf,v 1.6 2018/08/03 16:32:55 ryo Exp $
#-
# Copyright (c) 2014 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -120,6 +120,8 @@
define LX_BLKPAG_UXN LX_BLKPAG_UXN
define LX_BLKPAG_PXN LX_BLKPAG_PXN
define LX_BLKPAG_AF LX_BLKPAG_AF
+define LX_BLKPAG_AP LX_BLKPAG_AP
+define LX_BLKPAG_AP_RO LX_BLKPAG_AP_RO
define LX_BLKPAG_AP_RW LX_BLKPAG_AP_RW
define LX_BLKPAG_SH_IS LX_BLKPAG_SH_IS
define LX_BLKPAG_ATTR_INDX_0 LX_BLKPAG_ATTR_INDX_0
diff -r d117b972ffff -r 8673205d2861 sys/arch/aarch64/aarch64/locore.S
--- a/sys/arch/aarch64/aarch64/locore.S Fri Aug 03 16:31:04 2018 +0000
+++ b/sys/arch/aarch64/aarch64/locore.S Fri Aug 03 16:32:55 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.S,v 1.13 2018/07/17 18:08:36 christos Exp $ */
+/* $NetBSD: locore.S,v 1.14 2018/08/03 16:32:55 ryo Exp $ */
/*
* Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -35,7 +35,7 @@
#include <aarch64/hypervisor.h>
#include "assym.h"
-RCSID("$NetBSD: locore.S,v 1.13 2018/07/17 18:08:36 christos Exp $")
+RCSID("$NetBSD: locore.S,v 1.14 2018/08/03 16:32:55 ryo Exp $")
/* #define DEBUG_LOCORE */
/* #define DEBUG_MMU */
@@ -650,9 +650,44 @@
lsr x4, x4, #L2_SHIFT
bl l2_setblocks
+#ifndef DDB
+ /* map READONLY from VM_MIN_KERNEL_ADDRESS to __data_start */
+ VERBOSE("Set kernel text/rodata READONLY\r\n")
+ ldr x3, =__data_start
+ ands x0, x3, #(L2_SIZE - 1)
+ beq 1f
+ ldr x1, =_erodata
+ and x1, x1, #L2_ADDR_BITS /* _erodata & L2_ADDR_BIT */
+ and x0, x3, #L2_ADDR_BITS /* __data_start & L2_ADDR_BIT */
+ cmp x0, x1
+ bne 1f
+ /* __data_start and _erodata are in same L2 block */
+ PRINT("Warning: data section not aligned on size of L2 block\r\n")
+1:
+ /* x3 = l2pde_index(__data_start) */
+ and x3, x3, #L2_ADDR_BITS
+ lsr x3, x3, #L2_SHIFT
+
+ /* x2 = l2pde_inex(VM_MIN_KERNEL_ADDRESS) */
+ mov x2, #VM_MIN_KERNEL_ADDRESS
+ and x2, x2, #L2_ADDR_BITS
+ lsr x2, x2, #L2_SHIFT
+
+ ADDR x1, ttbr1_l2table_kva
+ b 9f
+1:
+ ldr x0, [x1, x2, lsl #3] /* x0 = l2table[x2] */
+ and x0, x0, #~LX_BLKPAG_AP
+ orr x0, x0, #LX_BLKPAG_AP_RO
+ str x0, [x1, x2, lsl #3] /* l2table[x2] = x0 */
+ add x2, x2, #1
+9:
+ cmp x2, x3
+ blo 1b
+#endif
+
VERBOSE("Creating devmap tables\r\n")
/* devmap=PA table for L1 */
-nop
ADDR x0, ttbr1_l1table_kva
ldr x1, .L_devmap_addr
ADDR x2, ttbr1_l2table_devmap
diff -r d117b972ffff -r 8673205d2861 sys/arch/aarch64/conf/kern.ldscript
--- a/sys/arch/aarch64/conf/kern.ldscript Fri Aug 03 16:31:04 2018 +0000
+++ b/sys/arch/aarch64/conf/kern.ldscript Fri Aug 03 16:32:55 2018 +0000
@@ -1,3 +1,5 @@
+#include "assym.h"
+
/* Default linker script, for normal executables */
OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64",
"elf64-littleaarch64")
@@ -30,9 +32,11 @@
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
- /* Adjust the address for the data segment. We want to adjust up to
- the same address within the page on the next page up. */
- . = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) & (CONSTANT (MAXPAGESIZE) - 1)); . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
+ /* Adjust the address for the data segment. Move .data to the next L2 block,
+ and .text and .rodata will be set readonly if needed. */
+ PROVIDE (_erodata = .);
+ . = ALIGN (L2_SIZE);
+ . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
/* Exception handling */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
Home |
Main Index |
Thread Index |
Old Index