arm64: warn on incorrect placement of the kernel by the bootloader
PATCH 1/1 arm64: warn on incorrect placement of the kernel by the bootloader
Commit cfa7ede20f133c ("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.
--- arch/arm64/Kconfig | 3 ++- arch/arm64/kernel/setup.c | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-)
arch/arm64/Kconfig +2 -1
@@ -1740,8 +1740,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
arch/arm64/kernel/setup.c +3 -0
@@ -319,6 +319,9 @@ void __init setup_arch(char **cmdline_p)xen_early_init ();efi_init (); +WARN (!efi_enabled (EFI_BOOT ) && ((u64 )_text %MIN_KIMG_ALIGN ) !=0 , +FW_BUG "Kernel image misaligned at boot, please fix your bootloader" ); +arm64_memblock_init ();paging_init ();
Signature · 7 lines
2.26.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon
maintainerQuoted 39 lines · Ard Biesheuvel
Commit
cfa7ede20f133c("arm64: setTEXT_OFFSETto0x0in preparation for removing it entirely") results in boot failures when booting kernels that are built without KASLR support on broken bootloaders that ignore theTEXT_OFFSETvalue passed via the header, and use the default of0x80000instead.To work around this, turn
CONFIG_RELOCATABLEon by default, even if KASLR itself (CONFIG_RANDOMIZE_BASE) is turned off, and requireCONFIG_EXPERTto 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 inDocumentation/arm64/booting.rst.Signed-off-by Ard Biesheuvel <[email protected]>--- arch/arm64/Kconfig | 3 ++- arch/arm64/kernel/setup.c | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-)arch/arm64/Kconfig +2
-1@@ -1740,8 +1740,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 thearch/arm64/kernel/setup.c +0
-0
arch/arm64/kernel/setup.c void __init setup_arch(char **cmdline_p) · line 323
Quoted 5 lines
arch/arm64/kernel/setup.c +2
-0@@ -319,6 +319,9 @@ void __init setup_arch(char **cmdline_p)xen_early_init ();efi_init (); +WARN (!efi_enabled (EFI_BOOT ) && ((u64 )_text %MIN_KIMG_ALIGN ) !=0 , +FW_BUG "Kernel image misaligned at boot, please fix your bootloader" );
I think pr_warn is probably sufficient here, as the backtrace isn't really helping anybody:
[ 0.000000] ------------[ cut here ]------------ [ 0.000000] [Firmware Bug]: Kernel image misaligned at boot, please fix your bootloader [ 0.000000] WARNING: CPU: 0 PID: 0 at arch/arm64/kernel/setup.c:323 setup_arch+0x208/0x214 [ 0.000000] Modules linked in: [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.7.0-rc3-00162-g16d1072f6b69 #1 [ 0.000000] Hardware name: linux,dummy-virt (DT) [ 0.000000] pstate: 60000085 (nZCv daIf -PAN -UAO BTYPE=--) [ 0.000000] pc : setup_arch+0x208/0x214 [ 0.000000] lr : setup_arch+0x208/0x214 [ 0.000000] sp : ffff800011b03f90 [ 0.000000] x29: ffff800011b03f90 x28: 0000000081580018 [ 0.000000] x27: 0000000000000000 x26: 0000000000000000 [ 0.000000] x25: 0000000000000000 x24: 0000000000000000 [ 0.000000] x23: 0000000000080000 x22: 0000000000000000 [ 0.000000] x21: 000000008fe00000 x20: ffff800011b09000 [ 0.000000] x19: ffff800010080000 x18: 000000000001fdd8 [ 0.000000] x17: 000000000000004a x16: ffff800011b03bf1 [ 0.000000] x15: 0000000000000000 x14: 6564616f6c746f6f [ 0.000000] x13: 0000000000000000 x12: 0000000000000000 [ 0.000000] x11: 0000000000000000 x10: 00000000ffffffff [ 0.000000] x9 : 0000000000000000 x8 : 0000000000000000 [ 0.000000] x7 : 000000000000004b x6 : ffff800011d41093 [ 0.000000] x5 : 000000000000004b x4 : 000000000000000c [ 0.000000] x3 : 0000000000000072 x2 : 000000000000003f [ 0.000000] x1 : ffff800011d3e75f x0 : 000000000000004b [ 0.000000] Call trace: [ 0.000000] setup_arch+0x208/0x214 [ 0.000000] start_kernel+0x70/0x3ec [ 0.000000] random: get_random_bytes called from __warn+0xe4/0x178 with crng_init=0 [ 0.000000] ---[ end trace 0000000000000000 ]---
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 42 lines · Will Deacon
Quoted 40 lines · Ard Biesheuvel
Commit
cfa7ede20f133c("arm64: setTEXT_OFFSETto0x0in preparation for removing it entirely") results in boot failures when booting kernels that are built without KASLR support on broken bootloaders that ignore theTEXT_OFFSETvalue passed via the header, and use the default of0x80000instead.To work around this, turn
CONFIG_RELOCATABLEon by default, even if KASLR itself (CONFIG_RANDOMIZE_BASE) is turned off, and requireCONFIG_EXPERTto 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 inDocumentation/arm64/booting.rst.Signed-off-by Ard Biesheuvel <[email protected]>--- arch/arm64/Kconfig | 3 ++- arch/arm64/kernel/setup.c | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-)arch/arm64/Kconfig +2
-1@@ -1740,8 +1740,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 thearch/arm64/kernel/setup.c +0
-0@@ -319,6 +319,9 @@ void __init setup_arch(char **cmdline_p)
Quoted 8 lines
arch/arm64/kernel/setup.c void __init setup_arch(char **cmdline_p) · line 323
Quoted 4 lines
arch/arm64/kernel/setup.c +2
-0xen_early_init ();efi_init (); +WARN (!efi_enabled (EFI_BOOT ) && ((u64 )_text %MIN_KIMG_ALIGN ) !=0 , +FW_BUG "Kernel image misaligned at boot, please fix your bootloader" );I think
pr_warnis probably sufficient here, as the backtrace isn't really helping anybody:
It makes it a bit more obnoxious, and so people are more likely to notice and care. But I agree that the backtrace serves no purpose.
I'll update that.
Quoted 31 lines
[ 0.000000] ------------[ cut here ]------------ [ 0.000000] [Firmware Bug]: Kernel image misaligned at boot, please fix your bootloader [ 0.000000] WARNING: CPU: 0 PID: 0 at arch/arm64/kernel/setup.c:323 setup_arch+0x208/0x214 [ 0.000000] Modules linked in: [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.7.0-rc3-00162-g16d1072f6b69 #1 [ 0.000000] Hardware name: linux,dummy-virt (DT) [ 0.000000] pstate: 60000085 (nZCv daIf -PAN -UAO BTYPE=--) [ 0.000000] pc : setup_arch+0x208/0x214 [ 0.000000] lr : setup_arch+0x208/0x214 [ 0.000000] sp : ffff800011b03f90 [ 0.000000] x29: ffff800011b03f90 x28: 0000000081580018 [ 0.000000] x27: 0000000000000000 x26: 0000000000000000 [ 0.000000] x25: 0000000000000000 x24: 0000000000000000 [ 0.000000] x23: 0000000000080000 x22: 0000000000000000 [ 0.000000] x21: 000000008fe00000 x20: ffff800011b09000 [ 0.000000] x19: ffff800010080000 x18: 000000000001fdd8 [ 0.000000] x17: 000000000000004a x16: ffff800011b03bf1 [ 0.000000] x15: 0000000000000000 x14: 6564616f6c746f6f [ 0.000000] x13: 0000000000000000 x12: 0000000000000000 [ 0.000000] x11: 0000000000000000 x10: 00000000ffffffff [ 0.000000] x9 : 0000000000000000 x8 : 0000000000000000 [ 0.000000] x7 : 000000000000004b x6 : ffff800011d41093 [ 0.000000] x5 : 000000000000004b x4 : 000000000000000c [ 0.000000] x3 : 0000000000000072 x2 : 000000000000003f [ 0.000000] x1 : ffff800011d3e75f x0 : 000000000000004b [ 0.000000] Call trace: [ 0.000000] setup_arch+0x208/0x214 [ 0.000000] start_kernel+0x70/0x3ec [ 0.000000] random: get_random_bytes called from __warn+0xe4/0x178 with crng_init=0 [ 0.000000] ---[ end trace 0000000000000000 ]---
Quoted 1 line
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel