Commit 7e502622 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Ingo Molnar

x86/efi: Disregard setup header of loaded image

The native EFI entrypoint does not take a struct boot_params from the
loader, but instead, it constructs one from scratch, using the setup
header data placed at the start of the image.

This setup header is placed in a way that permits legacy loaders to
manipulate the contents (i.e., to pass the kernel command line or the
address and size of an initial ramdisk), but EFI boot does not use it in
that way - it only copies the contents that were placed there at build
time, but EFI loaders will not (and should not) manipulate the setup
header to configure the boot. (Commit 63bf28ce "efi: x86: Wipe
setup_data on pure EFI boot" deals with some of the fallout of using
setup_data in a way that breaks EFI boot.)

Given that none of the non-zero values that are copied from the setup
header into the EFI stub's struct boot_params are relevant to the boot
now that the EFI stub no longer enters via the legacy decompressor, the
copy can be omitted altogether.
Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20230912090051.4014114-19-ardb@google.com
parent 5f51c5d0
...@@ -449,9 +449,8 @@ void __noreturn efi_stub_entry(efi_handle_t handle, ...@@ -449,9 +449,8 @@ void __noreturn efi_stub_entry(efi_handle_t handle,
efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
efi_system_table_t *sys_table_arg) efi_system_table_t *sys_table_arg)
{ {
struct boot_params *boot_params; static struct boot_params boot_params __page_aligned_bss;
struct setup_header *hdr; struct setup_header *hdr = &boot_params.hdr;
void *image_base;
efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID; efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID;
int options_size = 0; int options_size = 0;
efi_status_t status; efi_status_t status;
...@@ -469,30 +468,9 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, ...@@ -469,30 +468,9 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
efi_exit(handle, status); efi_exit(handle, status);
} }
image_base = efi_table_attr(image, image_base); /* Assign the setup_header fields that the kernel actually cares about */
status = efi_allocate_pages(sizeof(struct boot_params),
(unsigned long *)&boot_params, ULONG_MAX);
if (status != EFI_SUCCESS) {
efi_err("Failed to allocate lowmem for boot params\n");
efi_exit(handle, status);
}
memset(boot_params, 0x0, sizeof(struct boot_params));
hdr = &boot_params->hdr;
/* Copy the setup header from the second sector to boot_params */
memcpy(&hdr->jump, image_base + 512,
sizeof(struct setup_header) - offsetof(struct setup_header, jump));
/*
* Fill out some of the header fields ourselves because the
* EFI firmware loader doesn't load the first sector.
*/
hdr->root_flags = 1; hdr->root_flags = 1;
hdr->vid_mode = 0xffff; hdr->vid_mode = 0xffff;
hdr->boot_flag = 0xAA55;
hdr->type_of_loader = 0x21; hdr->type_of_loader = 0x21;
...@@ -501,25 +479,13 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, ...@@ -501,25 +479,13 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
if (!cmdline_ptr) if (!cmdline_ptr)
goto fail; goto fail;
efi_set_u64_split((unsigned long)cmdline_ptr, efi_set_u64_split((unsigned long)cmdline_ptr, &hdr->cmd_line_ptr,
&hdr->cmd_line_ptr, &boot_params->ext_cmd_line_ptr); &boot_params.ext_cmd_line_ptr);
hdr->ramdisk_image = 0;
hdr->ramdisk_size = 0;
/*
* Disregard any setup data that was provided by the bootloader:
* setup_data could be pointing anywhere, and we have no way of
* authenticating or validating the payload.
*/
hdr->setup_data = 0;
efi_stub_entry(handle, sys_table_arg, boot_params); efi_stub_entry(handle, sys_table_arg, &boot_params);
/* not reached */ /* not reached */
fail: fail:
efi_free(sizeof(struct boot_params), (unsigned long)boot_params);
efi_exit(handle, status); efi_exit(handle, status);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment