Skip to content

Commit af2a9c6

Browse files
committed
Merge tag 'efi-urgent-for-v6.7-2' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi
Pull EFI fixes from Ard Biesheuvel: - Deal with a regression in the recently refactored x86 EFI stub code on older Dell systems by disabling randomization of the physical load address - Use the correct load address for relocatable Loongarch kernels * tag 'efi-urgent-for-v6.7-2' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi: efi/x86: Avoid physical KASLR on older Dell systems efi/loongarch: Use load address to calculate kernel entry address
2 parents 88035e5 + 50d7cdf commit af2a9c6

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

arch/loongarch/include/asm/efi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ static inline unsigned long efi_get_kimg_min_align(void)
3232

3333
#define EFI_KIMG_PREFERRED_ADDRESS PHYSADDR(VMLINUX_LOAD_ADDRESS)
3434

35-
unsigned long kernel_entry_address(void);
35+
unsigned long kernel_entry_address(unsigned long kernel_addr);
3636

3737
#endif /* _ASM_LOONGARCH_EFI_H */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
3535
return status;
3636
}
3737

38-
unsigned long kernel_entry_address(void)
38+
unsigned long kernel_entry_address(unsigned long kernel_addr)
3939
{
4040
unsigned long base = (unsigned long)&kernel_offset - kernel_offset;
4141

42-
return (unsigned long)&kernel_entry - base + VMLINUX_LOAD_ADDRESS;
42+
return (unsigned long)&kernel_entry - base + kernel_addr;
4343
}

drivers/firmware/efi/libstub/loongarch.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ static efi_status_t exit_boot_func(struct efi_boot_memmap *map, void *priv)
3737
return EFI_SUCCESS;
3838
}
3939

40-
unsigned long __weak kernel_entry_address(void)
40+
unsigned long __weak kernel_entry_address(unsigned long kernel_addr)
4141
{
42-
return *(unsigned long *)(PHYSADDR(VMLINUX_LOAD_ADDRESS) + 8);
42+
return *(unsigned long *)(kernel_addr + 8) - VMLINUX_LOAD_ADDRESS + kernel_addr;
4343
}
4444

4545
efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
@@ -73,7 +73,7 @@ efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
7373
csr_write64(CSR_DMW0_INIT, LOONGARCH_CSR_DMWIN0);
7474
csr_write64(CSR_DMW1_INIT, LOONGARCH_CSR_DMWIN1);
7575

76-
real_kernel_entry = (void *)kernel_entry_address();
76+
real_kernel_entry = (void *)kernel_entry_address(kernel_addr);
7777

7878
real_kernel_entry(true, (unsigned long)cmdline_ptr,
7979
(unsigned long)efi_system_table);

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,17 +307,20 @@ static void setup_unaccepted_memory(void)
307307
efi_err("Memory acceptance protocol failed\n");
308308
}
309309

310+
static efi_char16_t *efistub_fw_vendor(void)
311+
{
312+
unsigned long vendor = efi_table_attr(efi_system_table, fw_vendor);
313+
314+
return (efi_char16_t *)vendor;
315+
}
316+
310317
static const efi_char16_t apple[] = L"Apple";
311318

312319
static void setup_quirks(struct boot_params *boot_params)
313320
{
314-
efi_char16_t *fw_vendor = (efi_char16_t *)(unsigned long)
315-
efi_table_attr(efi_system_table, fw_vendor);
316-
317-
if (!memcmp(fw_vendor, apple, sizeof(apple))) {
318-
if (IS_ENABLED(CONFIG_APPLE_PROPERTIES))
319-
retrieve_apple_device_properties(boot_params);
320-
}
321+
if (IS_ENABLED(CONFIG_APPLE_PROPERTIES) &&
322+
!memcmp(efistub_fw_vendor(), apple, sizeof(apple)))
323+
retrieve_apple_device_properties(boot_params);
321324
}
322325

323326
/*
@@ -765,11 +768,25 @@ static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry)
765768

766769
if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && !efi_nokaslr) {
767770
u64 range = KERNEL_IMAGE_SIZE - LOAD_PHYSICAL_ADDR - kernel_total_size;
771+
static const efi_char16_t ami[] = L"American Megatrends";
768772

769773
efi_get_seed(seed, sizeof(seed));
770774

771775
virt_addr += (range * seed[1]) >> 32;
772776
virt_addr &= ~(CONFIG_PHYSICAL_ALIGN - 1);
777+
778+
/*
779+
* Older Dell systems with AMI UEFI firmware v2.0 may hang
780+
* while decompressing the kernel if physical address
781+
* randomization is enabled.
782+
*
783+
* https://bugzilla.kernel.org/show_bug.cgi?id=218173
784+
*/
785+
if (efi_system_table->hdr.revision <= EFI_2_00_SYSTEM_TABLE_REVISION &&
786+
!memcmp(efistub_fw_vendor(), ami, sizeof(ami))) {
787+
efi_debug("AMI firmware v2.0 or older detected - disabling physical KASLR\n");
788+
seed[0] = 0;
789+
}
773790
}
774791

775792
status = efi_random_alloc(alloc_size, CONFIG_PHYSICAL_ALIGN, &addr,

0 commit comments

Comments
 (0)