efi/libstub: arm64: Force Image reallocation if BSS was not reserved
authorArd Biesheuvel <ardb@kernel.org>
Mon, 26 Jul 2021 09:38:41 +0000 (11:38 +0200)
committerArd Biesheuvel <ardb@kernel.org>
Tue, 3 Aug 2021 05:41:53 +0000 (07:41 +0200)
commit5b94046efb4706b3429c9c8e7377bd8d1621d588
treee6ee8665b59afa431278f81df88450f35e1f3f78
parent4152433c397697acc4b02c4a10d17d5859c2730d
efi/libstub: arm64: Force Image reallocation if BSS was not reserved

Distro versions of GRUB replace the usual LoadImage/StartImage calls
used to load the kernel image with some local code that fails to honor
the allocation requirements described in the PE/COFF header, as it
does not account for the image's BSS section at all: it fails to
allocate space for it, and fails to zero initialize it.

Since the EFI stub itself is allocated in the .init segment, which is
in the middle of the image, its BSS section is not impacted by this,
and the main consequence of this omission is that the BSS section may
overlap with memory regions that are already used by the firmware.

So let's warn about this condition, and force image reallocation to
occur in this case, which works around the problem.

Fixes: 82046702e288 ("efi/libstub/arm64: Replace 'preferred' offset with alignment check")
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Tested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
drivers/firmware/efi/libstub/arm64-stub.c