Skip to content

Commit 5499315

Browse files
committed
Merge tag 'efi-fixes-for-v6.10-1' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi
Pull EFI fix from Ard Biesheuvel: - Followup fix for the EFI boot sequence refactor, which may result in physical KASLR putting the kernel in a region which is being used for a special purpose via a command line argument. * tag 'efi-fixes-for-v6.10-1' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi: x86/efistub: Omit physical KASLR when memory reservations exist
2 parents 8567263 + 15aa8fb commit 5499315

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,26 @@ static void error(char *str)
776776
efi_warn("Decompression failed: %s\n", str);
777777
}
778778

779+
static const char *cmdline_memmap_override;
780+
781+
static efi_status_t parse_options(const char *cmdline)
782+
{
783+
static const char opts[][14] = {
784+
"mem=", "memmap=", "efi_fake_mem=", "hugepages="
785+
};
786+
787+
for (int i = 0; i < ARRAY_SIZE(opts); i++) {
788+
const char *p = strstr(cmdline, opts[i]);
789+
790+
if (p == cmdline || (p > cmdline && isspace(p[-1]))) {
791+
cmdline_memmap_override = opts[i];
792+
break;
793+
}
794+
}
795+
796+
return efi_parse_options(cmdline);
797+
}
798+
779799
static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry)
780800
{
781801
unsigned long virt_addr = LOAD_PHYSICAL_ADDR;
@@ -807,6 +827,10 @@ static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry)
807827
!memcmp(efistub_fw_vendor(), ami, sizeof(ami))) {
808828
efi_debug("AMI firmware v2.0 or older detected - disabling physical KASLR\n");
809829
seed[0] = 0;
830+
} else if (cmdline_memmap_override) {
831+
efi_info("%s detected on the kernel command line - disabling physical KASLR\n",
832+
cmdline_memmap_override);
833+
seed[0] = 0;
810834
}
811835

812836
boot_params_ptr->hdr.loadflags |= KASLR_FLAG;
@@ -883,7 +907,7 @@ void __noreturn efi_stub_entry(efi_handle_t handle,
883907
}
884908

885909
#ifdef CONFIG_CMDLINE_BOOL
886-
status = efi_parse_options(CONFIG_CMDLINE);
910+
status = parse_options(CONFIG_CMDLINE);
887911
if (status != EFI_SUCCESS) {
888912
efi_err("Failed to parse options\n");
889913
goto fail;
@@ -892,7 +916,7 @@ void __noreturn efi_stub_entry(efi_handle_t handle,
892916
if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) {
893917
unsigned long cmdline_paddr = ((u64)hdr->cmd_line_ptr |
894918
((u64)boot_params->ext_cmd_line_ptr << 32));
895-
status = efi_parse_options((char *)cmdline_paddr);
919+
status = parse_options((char *)cmdline_paddr);
896920
if (status != EFI_SUCCESS) {
897921
efi_err("Failed to parse options\n");
898922
goto fail;

0 commit comments

Comments
 (0)