aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Rutland <mark.rutland@arm.com>2014-06-24 11:51:37 -0400
committerCatalin Marinas <catalin.marinas@arm.com>2014-07-10 07:36:58 -0400
commitda57a369d3bc5cd61db90f7e9555840381db9b09 (patch)
tree6e2e032c24d4b36e792e91984191752f527baf09
parenta2c1d73b94ed49f5fac12e95052d7b140783f800 (diff)
arm64: Enable TEXT_OFFSET fuzzing
The arm64 Image header contains a text_offset field which bootloaders are supposed to read to determine the offset (from a 2MB aligned "start of memory" per booting.txt) at which to load the kernel. The offset is not well respected by bootloaders at present, and due to the lack of variation there is little incentive to support it. This is unfortunate for the sake of future kernels where we may wish to vary the text offset (even zeroing it). This patch adds options to arm64 to enable fuzz-testing of text_offset. CONFIG_ARM64_RANDOMIZE_TEXT_OFFSET forces the text offset to a random 16-byte aligned value value in the range [0..2MB) upon a build of the kernel. It is recommended that distribution kernels enable randomization to test bootloaders such that any compliance issues can be fixed early. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Acked-by: Tom Rini <trini@ti.com> Acked-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
-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")