Skip to content

Commit b3810c5

Browse files
committed
x86/efistub: Clear decompressor BSS in native EFI entrypoint
The EFI stub on x86 no longer invokes the decompressor as a subsequent boot stage, but calls into the decompression code directly while running in the context of the EFI boot services. This means that when using the native EFI entrypoint (as opposed to the EFI handover protocol, which clears BSS explicitly), the firmware PE image loader is being relied upon to ensure that BSS is zeroed before the EFI stub is entered from the firmware. As Radek's report proves, this is a bad idea. Not all loaders do this correctly, which means some global variables that should be statically initialized to 0x0 may have junk in them. So clear BSS explicitly when entering via efi_pe_entry(). Note that zeroing BSS from C code is not generally safe, but in this case, the following assignment and dereference of a global pointer variable ensures that the memset() cannot be deferred or reordered. Cc: <[email protected]> # v6.1+ Reported-by: Radek Podgorny <[email protected]> Closes: https://lore.kernel.org/all/[email protected] Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent 021bc4b commit b3810c5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "efistub.h"
2222
#include "x86-stub.h"
2323

24+
extern char _bss[], _ebss[];
25+
2426
const efi_system_table_t *efi_system_table;
2527
const efi_dxe_services_table_t *efi_dxe_table;
2628
static efi_loaded_image_t *image = NULL;
@@ -474,6 +476,8 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
474476
efi_status_t status;
475477
char *cmdline_ptr;
476478

479+
memset(_bss, 0, _ebss - _bss);
480+
477481
efi_system_table = sys_table_arg;
478482

479483
/* Check if we were booted by the EFI firmware */
@@ -967,8 +971,6 @@ void __noreturn efi_stub_entry(efi_handle_t handle,
967971
void efi_handover_entry(efi_handle_t handle, efi_system_table_t *sys_table_arg,
968972
struct boot_params *boot_params)
969973
{
970-
extern char _bss[], _ebss[];
971-
972974
memset(_bss, 0, _ebss - _bss);
973975
efi_stub_entry(handle, sys_table_arg, boot_params);
974976
}

0 commit comments

Comments
 (0)