x86/efistub: Clear BSS in EFI handover protocol entrypoint
authorArd Biesheuvel <ardb@kernel.org>
Mon, 7 Aug 2023 16:27:03 +0000 (18:27 +0200)
committerBorislav Petkov (AMD) <bp@alien8.de>
Mon, 7 Aug 2023 18:40:36 +0000 (20:40 +0200)
commitd7156b986d4cc0657fa6dc05c9fcf51c3d55a0fe
tree9810091771de88189b6be31a3a3f79c9fc1c9cc3
parent12792064587623065250069d1df980e2c9ac3e67
x86/efistub: Clear BSS in EFI handover protocol entrypoint

The so-called EFI handover protocol is value-add from the distros that
permits a loader to simply copy a PE kernel image into memory and call
an alternative entrypoint that is described by an embedded boot_params
structure.

Most implementations of this protocol do not bother to check the PE
header for minimum alignment, section placement, etc, and therefore also
don't clear the image's BSS, or even allocate enough memory for it.

Allocating more memory on the fly is rather difficult, but at least
clear the BSS region explicitly when entering in this manner, so that
the EFI stub code does not get confused by global variables that were
not zero-initialized correctly.

When booting in mixed mode, this BSS clearing must occur before any
global state is created, so clear it in the 32-bit asm entry point.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/20230807162720.545787-7-ardb@kernel.org
arch/x86/boot/compressed/efi_mixed.S
drivers/firmware/efi/libstub/x86-stub.c