Skip to content

Commit

Permalink
arm64: warn on incorrect placement of the kernel by the bootloader
Browse files Browse the repository at this point in the history
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 <ardb@kernel.org>
Link: https://lore.kernel.org/r/20200611124330.252163-1-ardb@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>
  • Loading branch information
Ard Biesheuvel authored and Will Deacon committed Jun 11, 2020
1 parent a194c33 commit dd4bc60
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion arch/arm64/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1746,8 +1746,9 @@ config ARM64_DEBUG_PRIORITY_MASKING
endif

config RELOCATABLE
bool
bool "Build a relocatable kernel image" if EXPERT
select ARCH_HAS_RELR
default y
help
This builds the kernel as a Position Independent Executable (PIE),
which retains all relocation metadata required to relocate the
Expand Down
4 changes: 4 additions & 0 deletions arch/arm64/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ void __init setup_arch(char **cmdline_p)

xen_early_init();
efi_init();

if (!efi_enabled(EFI_BOOT) && ((u64)_text % MIN_KIMG_ALIGN) != 0)
pr_warn(FW_BUG "Kernel image misaligned at boot, please fix your bootloader!");

arm64_memblock_init();

paging_init();
Expand Down

0 comments on commit dd4bc60

Please sign in to comment.