Skip to content

Commit 63bf28c

Browse files
committed
efi: x86: Wipe setup_data on pure EFI boot
When booting the x86 kernel via EFI using the LoadImage/StartImage boot services [as opposed to the deprecated EFI handover protocol], the setup header is taken from the image directly, and given that EFI's LoadImage has no Linux/x86 specific knowledge regarding struct bootparams or struct setup_header, any absolute addresses in the setup header must originate from the file and not from a prior loading stage. Since we cannot generally predict where LoadImage() decides to load an image (*), such absolute addresses must be treated as suspect: even if a prior boot stage intended to make them point somewhere inside the [signed] image, there is no way to validate that, and if they point at an arbitrary location in memory, the setup_data nodes will not be covered by any signatures or TPM measurements either, and could be made to contain an arbitrary sequence of SETUP_xxx nodes, which could interfere quite badly with the early x86 boot sequence. (*) Note that, while LoadImage() does take a buffer/size tuple in addition to a device path, which can be used to provide the image contents directly, it will re-allocate such images, as the memory footprint of an image is generally larger than the PE/COFF file representation. Cc: <[email protected]> # v5.10+ Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Ard Biesheuvel <[email protected]> Acked-by: Jason A. Donenfeld <[email protected]>
1 parent 7da5b13 commit 63bf28c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,13 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
516516
hdr->ramdisk_image = 0;
517517
hdr->ramdisk_size = 0;
518518

519+
/*
520+
* Disregard any setup data that was provided by the bootloader:
521+
* setup_data could be pointing anywhere, and we have no way of
522+
* authenticating or validating the payload.
523+
*/
524+
hdr->setup_data = 0;
525+
519526
efi_stub_entry(handle, sys_table_arg, boot_params);
520527
/* not reached */
521528

0 commit comments

Comments
 (0)