Skip to content

Commit 01e5990

Browse files
committed
Merge: x86/efistub: Omit physical KASLR when memory reservations exist
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/6577 JIRA: https://issues.redhat.com/browse/RHEL-83461 This patch is a backport of the following upstream commit: commit 15aa8fb Author: Ard Biesheuvel <ardb@kernel.org> Date: Thu May 16 11:05:42 2024 +0200 Signed-off-by: Charles Haithcock <chaithco@redhat.com> Approved-by: Ricardo Robaina <rrobaina@redhat.com> Approved-by: Rafael Aquini <raquini@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Augusto Caringi <acaringi@redhat.com>
2 parents 85a5dcb + 253807f commit 01e5990

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
@@ -770,6 +770,26 @@ static void error(char *str)
770770
efi_warn("Decompression failed: %s\n", str);
771771
}
772772

773+
static const char *cmdline_memmap_override;
774+
775+
static efi_status_t parse_options(const char *cmdline)
776+
{
777+
static const char opts[][14] = {
778+
"mem=", "memmap=", "efi_fake_mem=", "hugepages="
779+
};
780+
781+
for (int i = 0; i < ARRAY_SIZE(opts); i++) {
782+
const char *p = strstr(cmdline, opts[i]);
783+
784+
if (p == cmdline || (p > cmdline && isspace(p[-1]))) {
785+
cmdline_memmap_override = opts[i];
786+
break;
787+
}
788+
}
789+
790+
return efi_parse_options(cmdline);
791+
}
792+
773793
static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry)
774794
{
775795
unsigned long virt_addr = LOAD_PHYSICAL_ADDR;
@@ -801,6 +821,10 @@ static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry)
801821
!memcmp(efistub_fw_vendor(), ami, sizeof(ami))) {
802822
efi_debug("AMI firmware v2.0 or older detected - disabling physical KASLR\n");
803823
seed[0] = 0;
824+
} else if (cmdline_memmap_override) {
825+
efi_info("%s detected on the kernel command line - disabling physical KASLR\n",
826+
cmdline_memmap_override);
827+
seed[0] = 0;
804828
}
805829

806830
boot_params_ptr->hdr.loadflags |= KASLR_FLAG;
@@ -877,7 +901,7 @@ void __noreturn efi_stub_entry(efi_handle_t handle,
877901
}
878902

879903
#ifdef CONFIG_CMDLINE_BOOL
880-
status = efi_parse_options(CONFIG_CMDLINE);
904+
status = parse_options(CONFIG_CMDLINE);
881905
if (status != EFI_SUCCESS) {
882906
efi_err("Failed to parse options\n");
883907
goto fail;
@@ -886,7 +910,7 @@ void __noreturn efi_stub_entry(efi_handle_t handle,
886910
if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) {
887911
unsigned long cmdline_paddr = ((u64)hdr->cmd_line_ptr |
888912
((u64)boot_params->ext_cmd_line_ptr << 32));
889-
status = efi_parse_options((char *)cmdline_paddr);
913+
status = parse_options((char *)cmdline_paddr);
890914
if (status != EFI_SUCCESS) {
891915
efi_err("Failed to parse options\n");
892916
goto fail;

0 commit comments

Comments
 (0)