Ben reported that distro GRUB may fail to boot in some circumstances,
and tracked it down to an issue in the way distro GRUB allocates space
for the image. Due to an oversight (addressed in patch #2), this
condition is rarely triggered, but let's work around it in any case (#1)
Remaining patches add further warnings for conditions that are unlikely
to occur, but should not be ignored.
Build tested only.
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Ard Biesheuvel (4):
efi/libstub: arm64: Force Image reallocation if BSS was not reserved
efi/libstub: arm64: Relax 2M alignment again for relocatable kernels
efi/libstub: arm64: Warn when efi_random_alloc() fails
efi/libstub: arm64: Double check image alignment at entry
drivers/firmware/efi/libstub/arm64-stub.c | 71 +++++++++++++++++---
1 file changed, 61 insertions(+), 10 deletions(-)
--
2.20.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
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: <redacted> # v5.10+
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/libstub/arm64-stub.c | 4 ++++
1 file changed, 4 insertions(+)
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>
---
drivers/firmware/efi/libstub/arm64-stub.c | 49 +++++++++++++++++++-
1 file changed, 48 insertions(+), 1 deletion(-)
Commit 82046702e288 ("efi/libstub/arm64: Replace 'preferred' offset with
alignment check") simplified the way the stub moves the kernel image
around in memory before booting it, given that a relocatable image does
not need to be copied to a 2M aligned offset if it was loaded on a 64k
boundary by EFI.
Commit d32de9130f6c ("efi/arm64: libstub: Deal gracefully with
EFI_RNG_PROTOCOL failure") inadvertently defeated this logic by
overriding the value of efi_nokaslr if EFI_RNG_PROTOCOL is not
available, which was mistaked by the loader logic as an explicit request
on the part of the user to disable KASLR and any associated relocation
of an Image not loaded on a 2M boundary.
So let's reinstate this functionality, by capturing the value of
efi_nokaslr at function entry to choose the minimum alignment.
Fixes: d32de9130f6c ("efi/arm64: libstub: Deal gracefully with EFI_RNG_PROTOCOL failure")
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/libstub/arm64-stub.c | 28 +++++++++-----------
1 file changed, 13 insertions(+), 15 deletions(-)
Randomization of the physical load address of the kernel image relies on
efi_random_alloc() returning successfully, and currently, we ignore any
failures and just carry on, using the ordinary, non-randomized page
allocator routine. This means we never find out if a failure occurs,
which could harm security, so let's at least warn about this condition.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/libstub/arm64-stub.c | 2 ++
1 file changed, 2 insertions(+)
From: Benjamin Herrenschmidt <benh@kernel.crashing.org> Date: 2021-08-02 11:33:28
On Mon, 2021-07-26 at 16:51 +0200, Ard Biesheuvel wrote:
Ben reported that distro GRUB may fail to boot in some circumstances,
and tracked it down to an issue in the way distro GRUB allocates space
for the image. Due to an oversight (addressed in patch #2), this
condition is rarely triggered, but let's work around it in any case (#1)
Remaining patches add further warnings for conditions that are unlikely
to occur, but should not be ignored.
Build tested only.
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
All 4 patches:
Tested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
I checked that it catches all of the errors, including reverting my fix
for randomalloc.c and verifying that it caught (and successfully worked
around) the original boot crash.
Cheers,
Ben.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Mon, 2 Aug 2021 at 13:26, Benjamin Herrenschmidt
[off-list ref] wrote:
On Mon, 2021-07-26 at 16:51 +0200, Ard Biesheuvel wrote:
quoted
Ben reported that distro GRUB may fail to boot in some circumstances,
and tracked it down to an issue in the way distro GRUB allocates space
for the image. Due to an oversight (addressed in patch #2), this
condition is rarely triggered, but let's work around it in any case (#1)
Remaining patches add further warnings for conditions that are unlikely
to occur, but should not be ignored.
Build tested only.
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
All 4 patches:
Tested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
I checked that it catches all of the errors, including reverting my fix
for randomalloc.c and verifying that it caught (and successfully worked
around) the original boot crash.
Excellent. Thanks for tracking this down and getting it fixed properly.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel