lkml.org 
[lkml]   [2017]   [Nov]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 17/18] arm64: makefile: Ensure TEXT_OFFSET doesn't overlap with trampoline
Date
When CONFIG_ARM64_RANDOMIZE_TEXT_OFFSET=y, we could end up with a
TEXT_OFFSET of less than 2 * PAGE_SIZE, which would result in an
overlap with the trampoline and a panic on boot.

Fix this by restricting the minimum value of the random TEXT_OFFSET
value so that it is not less than 2 pages when CONFIG_UNMAP_KERNEL_AT_EL0
is enabled.

I do wonder whether we should just remove
CONFIG_ARM64_RANDOMIZE_TEXT_OFFSET completely, since we're realistically
never going to be able to change our offset from 0x80000, but this keeps
the dream alive for now.

Signed-off-by: Will Deacon <will.deacon@arm.com>
---
arch/arm64/Makefile | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 939b310913cf..b60ac6c43ccd 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -87,9 +87,21 @@ head-y := arch/arm64/kernel/head.o

# The byte offset of the kernel image in RAM from the start of RAM.
ifeq ($(CONFIG_ARM64_RANDOMIZE_TEXT_OFFSET), y)
-TEXT_OFFSET := $(shell awk "BEGIN {srand(); printf \"0x%06x\n\", \
- int(2 * 1024 * 1024 / (2 ^ $(CONFIG_ARM64_PAGE_SHIFT)) * \
- rand()) * (2 ^ $(CONFIG_ARM64_PAGE_SHIFT))}")
+TEXT_OFFSET := $(shell awk \
+ "BEGIN { \
+ srand(); \
+ page_size = 2 ^ $(CONFIG_ARM64_PAGE_SHIFT); \
+ tramp_size = 0; \
+ if (\" $(CONFIG_UNMAP_KERNEL_AT_EL0)\" == \" y\") { \
+ tramp_size = 2 * page_size; \
+ } \
+ offset = int(2 * 1024 * 1024 / page_size * rand()); \
+ offset *= page_size; \
+ if (offset < tramp_size) { \
+ offset = tramp_size; \
+ } \
+ printf \"0x%06x\n\", offset; \
+ }")
else
TEXT_OFFSET := 0x00080000
endif
--
2.1.4
\
 
 \ /
  Last update: 2017-11-17 19:24    [W:0.188 / U:0.416 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site