aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firmware
diff options
context:
space:
mode:
authorArd Biesheuvel <ardb@kernel.org>2021-07-26 16:31:44 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-08-18 08:59:17 +0200
commit4a948c579ed6a12e248da57b9422a69b1ca2261c (patch)
treeecca333e5c3781c9d67c3b4568f7d332213c3d8f /drivers/firmware
parentfc7da433fa16b7e9a9efa92b41f684670535d99e (diff)
downloadkernel_replicant_linux-4a948c579ed6a12e248da57b9422a69b1ca2261c.tar.gz
kernel_replicant_linux-4a948c579ed6a12e248da57b9422a69b1ca2261c.tar.bz2
kernel_replicant_linux-4a948c579ed6a12e248da57b9422a69b1ca2261c.zip
efi/libstub: arm64: Double check image alignment at entry
commit c32ac11da3f83bb42b986702a9b92f0a14ed4182 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/firmware')
-rw-r--r--drivers/firmware/efi/libstub/arm64-stub.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c
index 881e157fdedc..c1b57dfb1277 100644
--- a/drivers/firmware/efi/libstub/arm64-stub.c
+++ b/drivers/firmware/efi/libstub/arm64-stub.c
@@ -119,6 +119,10 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
if (image->image_base != _text)
efi_err("FIRMWARE BUG: efi_loaded_image_t::image_base has bogus value\n");
+ if (!IS_ALIGNED((u64)_text, EFI_KIMG_ALIGN))
+ efi_err("FIRMWARE BUG: kernel image not aligned on %ldk boundary\n",
+ EFI_KIMG_ALIGN >> 10);
+
kernel_size = _edata - _text;
kernel_memsize = kernel_size + (_end - _edata);
*reserve_size = kernel_memsize;