Merge tag 'efi-fixes-for-v6.9-2' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorLinus Torvalds <torvalds@linux-foundation.org>
Sun, 24 Mar 2024 20:54:06 +0000 (13:54 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 24 Mar 2024 20:54:06 +0000 (13:54 -0700)
Pull EFI fixes from Ard Biesheuvel:

 - Fix logic that is supposed to prevent placement of the kernel image
   below LOAD_PHYSICAL_ADDR

 - Use the firmware stack in the EFI stub when running in mixed mode

 - Clear BSS only once when using mixed mode

 - Check efi.get_variable() function pointer for NULL before trying to
   call it

* tag 'efi-fixes-for-v6.9-2' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi:
  efi: fix panic in kdump kernel
  x86/efistub: Don't clear BSS twice in mixed mode
  x86/efistub: Call mixed mode boot services on the firmware's stack
  efi/libstub: fix efi_random_alloc() to allocate memory at alloc_min or higher address

arch/x86/boot/compressed/efi_mixed.S
drivers/firmware/efi/efi.c
drivers/firmware/efi/libstub/randomalloc.c
drivers/firmware/efi/libstub/x86-stub.c

index f4e22ef774ab6b4a0702d0e608007a994cec3fbe..719e939050cbfa0b9d574b326d46c4791a0a3eed 100644 (file)
@@ -49,6 +49,11 @@ SYM_FUNC_START(startup_64_mixed_mode)
        lea     efi32_boot_args(%rip), %rdx
        mov     0(%rdx), %edi
        mov     4(%rdx), %esi
+
+       /* Switch to the firmware's stack */
+       movl    efi32_boot_sp(%rip), %esp
+       andl    $~7, %esp
+
 #ifdef CONFIG_EFI_HANDOVER_PROTOCOL
        mov     8(%rdx), %edx           // saved bootparams pointer
        test    %edx, %edx
@@ -254,6 +259,9 @@ SYM_FUNC_START_LOCAL(efi32_entry)
        /* Store firmware IDT descriptor */
        sidtl   (efi32_boot_idt - 1b)(%ebx)
 
+       /* Store firmware stack pointer */
+       movl    %esp, (efi32_boot_sp - 1b)(%ebx)
+
        /* Store boot arguments */
        leal    (efi32_boot_args - 1b)(%ebx), %ebx
        movl    %ecx, 0(%ebx)
@@ -318,5 +326,6 @@ SYM_DATA_END(efi32_boot_idt)
 
 SYM_DATA_LOCAL(efi32_boot_cs, .word 0)
 SYM_DATA_LOCAL(efi32_boot_ds, .word 0)
+SYM_DATA_LOCAL(efi32_boot_sp, .long 0)
 SYM_DATA_LOCAL(efi32_boot_args, .long 0, 0, 0)
 SYM_DATA(efi_is64, .byte 1)
index 8859fb0b006d3b852225ffdd4040389844522cee..fdf07dd6f4591ddd4c32a80a2cf940e3d8b9d6f0 100644 (file)
@@ -203,6 +203,8 @@ static bool generic_ops_supported(void)
 
        name_size = sizeof(name);
 
+       if (!efi.get_next_variable)
+               return false;
        status = efi.get_next_variable(&name_size, &name, &guid);
        if (status == EFI_UNSUPPORTED)
                return false;
index 4e96a855fdf47b5b064b63b729d7dc989cd2b949..7e185285955021cb66a1a3a5fb4d6c24fc651b33 100644 (file)
@@ -120,7 +120,7 @@ efi_status_t efi_random_alloc(unsigned long size,
                        continue;
                }
 
-               target = round_up(md->phys_addr, align) + target_slot * align;
+               target = round_up(max(md->phys_addr, alloc_min), align) + target_slot * align;
                pages = size / EFI_PAGE_SIZE;
 
                status = efi_bs_call(allocate_pages, EFI_ALLOCATE_ADDRESS,
index 57888614e90f16b34f1e8b9cedd1341eca0697e5..6a6ffc6707bd0eb31e9dd13a995095760883e47c 100644 (file)
@@ -476,7 +476,8 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
        efi_status_t status;
        char *cmdline_ptr;
 
-       memset(_bss, 0, _ebss - _bss);
+       if (efi_is_native())
+               memset(_bss, 0, _ebss - _bss);
 
        efi_system_table = sys_table_arg;