aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm64
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm64')
-rw-r--r--arch/arm64/Kconfig.debug15
-rw-r--r--arch/arm64/Makefile4
-rw-r--r--arch/arm64/kernel/head.S8
-rw-r--r--arch/arm64/kernel/vmlinux.lds.S5
4 files changed, 30 insertions, 2 deletions
diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug
index 1c1b75629842..4ee8e90b7a45 100644
--- a/arch/arm64/Kconfig.debug
+++ b/arch/arm64/Kconfig.debug
@@ -28,4 +28,19 @@ config PID_IN_CONTEXTIDR
28 instructions during context switch. Say Y here only if you are 28 instructions during context switch. Say Y here only if you are
29 planning to use hardware trace tools with this kernel. 29 planning to use hardware trace tools with this kernel.
30 30
31config ARM64_RANDOMIZE_TEXT_OFFSET
32 bool "Randomize TEXT_OFFSET at build time"
33 help
34 Say Y here if you want the image load offset (AKA TEXT_OFFSET)
35 of the kernel to be randomized at build-time. When selected,
36 this option will cause TEXT_OFFSET to be randomized upon any
37 build of the kernel, and the offset will be reflected in the
38 text_offset field of the resulting Image. This can be used to
39 fuzz-test bootloaders which respect text_offset.
40
41 This option is intended for bootloader and/or kernel testing
42 only. Bootloaders must make no assumptions regarding the value
43 of TEXT_OFFSET and platforms must not require a specific
44 value.
45
31endmenu 46endmenu
diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 8185a913c5ed..e8d025c1459e 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -38,7 +38,11 @@ CHECKFLAGS += -D__aarch64__
38head-y := arch/arm64/kernel/head.o 38head-y := arch/arm64/kernel/head.o
39 39
40# The byte offset of the kernel image in RAM from the start of RAM. 40# The byte offset of the kernel image in RAM from the start of RAM.
41ifeq ($(CONFIG_ARM64_RANDOMIZE_TEXT_OFFSET), y)
42TEXT_OFFSET := $(shell awk 'BEGIN {srand(); printf "0x%04x0\n", int(65535 * rand())}')
43else
41TEXT_OFFSET := 0x00080000 44TEXT_OFFSET := 0x00080000
45endif
42 46
43export TEXT_OFFSET GZFLAGS 47export TEXT_OFFSET GZFLAGS
44 48
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index 3ba0fc02c0de..69dafe9621fd 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -37,8 +37,12 @@
37 37
38#define KERNEL_RAM_VADDR (PAGE_OFFSET + TEXT_OFFSET) 38#define KERNEL_RAM_VADDR (PAGE_OFFSET + TEXT_OFFSET)
39 39
40#if (KERNEL_RAM_VADDR & 0xfffff) != 0x80000 40#if (TEXT_OFFSET & 0xf) != 0
41#error KERNEL_RAM_VADDR must start at 0xXXX80000 41#error TEXT_OFFSET must be at least 16B aligned
42#elif (PAGE_OFFSET & 0xfffff) != 0
43#error PAGE_OFFSET must be at least 2MB aligned
44#elif TEXT_OFFSET > 0xfffff
45#error TEXT_OFFSET must be less than 2MB
42#endif 46#endif
43 47
44 .macro pgtbl, ttb0, ttb1, virt_to_phys 48 .macro pgtbl, ttb0, ttb1, virt_to_phys
diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index a814768ae148..97f0c0429dfa 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -125,3 +125,8 @@ SECTIONS
125 */ 125 */
126ASSERT(((__hyp_idmap_text_start + PAGE_SIZE) > __hyp_idmap_text_end), 126ASSERT(((__hyp_idmap_text_start + PAGE_SIZE) > __hyp_idmap_text_end),
127 "HYP init code too big") 127 "HYP init code too big")
128
129/*
130 * If padding is applied before .head.text, virt<->phys conversions will fail.
131 */
132ASSERT(_text == (PAGE_OFFSET + TEXT_OFFSET), "HEAD is misaligned")