Skip to content

Commit c32ac11

Browse files
committed
efi/libstub: arm64: Double check image alignment at entry
On arm64, the stub only moves the kernel image around in memory if needed, which is typically only for KASLR, given that relocatable kernels (which is the default) can run from any 64k aligned address, which is also the minimum alignment communicated to EFI via the PE/COFF header. Unfortunately, some loaders appear to ignore this header, and load the kernel at some arbitrary offset in memory. We can deal with this, but let's check for this condition anyway, so non-compliant code can be spotted and fixed. Cc: <stable@vger.kernel.org> # v5.10+ Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Tested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
1 parent ff80ef5 commit c32ac11

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

drivers/firmware/efi/libstub/arm64-stub.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
119119
if (image->image_base != _text)
120120
efi_err("FIRMWARE BUG: efi_loaded_image_t::image_base has bogus value\n");
121121

122+
if (!IS_ALIGNED((u64)_text, EFI_KIMG_ALIGN))
123+
efi_err("FIRMWARE BUG: kernel image not aligned on %ldk boundary\n",
124+
EFI_KIMG_ALIGN >> 10);
125+
122126
kernel_size = _edata - _text;
123127
kernel_memsize = kernel_size + (_end - _edata);
124128
*reserve_size = kernel_memsize;

0 commit comments

Comments
 (0)