Skip to content

Commit dd4bc60

Browse files
ardbiesheuvelwilldeacon
authored andcommitted
arm64: warn on incorrect placement of the kernel by the bootloader
Commit cfa7ede ("arm64: set TEXT_OFFSET to 0x0 in preparation for removing it entirely") results in boot failures when booting kernels that are built without KASLR support on broken bootloaders that ignore the TEXT_OFFSET value passed via the header, and use the default of 0x80000 instead. To work around this, turn CONFIG_RELOCATABLE on by default, even if KASLR itself (CONFIG_RANDOMIZE_BASE) is turned off, and require CONFIG_EXPERT to be enabled to deviate from this. Then, emit a warning into the kernel log if we are not booting via the EFI stub (which is permitted to deviate from the placement restrictions) and the kernel base address is not placed according to the rules as laid out in Documentation/arm64/booting.rst. Signed-off-by: Ard Biesheuvel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent a194c33 commit dd4bc60

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

arch/arm64/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1746,8 +1746,9 @@ config ARM64_DEBUG_PRIORITY_MASKING
17461746
endif
17471747

17481748
config RELOCATABLE
1749-
bool
1749+
bool "Build a relocatable kernel image" if EXPERT
17501750
select ARCH_HAS_RELR
1751+
default y
17511752
help
17521753
This builds the kernel as a Position Independent Executable (PIE),
17531754
which retains all relocation metadata required to relocate the

arch/arm64/kernel/setup.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ void __init setup_arch(char **cmdline_p)
319319

320320
xen_early_init();
321321
efi_init();
322+
323+
if (!efi_enabled(EFI_BOOT) && ((u64)_text % MIN_KIMG_ALIGN) != 0)
324+
pr_warn(FW_BUG "Kernel image misaligned at boot, please fix your bootloader!");
325+
322326
arm64_memblock_init();
323327

324328
paging_init();

0 commit comments

Comments
 (0)