Skip to contentSkip to conversation

efi: Wipe INITRD config table from memory after consumption

PATCH In review Ard Biesheuvel 1 participant 2 messages Dec 5, 2025 – Jan 8 EFI

lore
Share & tools
lore

Ard Biesheuvel

author maintainer
#0 lore raw

PATCH 1/1 efi: Wipe INITRD config table from memory after consumption

When the EFI stub itself loads the initrd and puts it in memory (rather than simply passing on a struct boot_params or device tree that already carries initrd information), it exposes this information to the core kernel via a INITRD configuration table.

Given that config tables are preserved across kexec, this means that subsequent kexec boots will observe the same information, even though it most likely has become stale by that point. On x86, this information is usually superseded by the initrd info passed via bootparams, in which case this stale information is simply ignored. However, when performing a kexec boot without passing an initrd, the loader falls back to this stale information and explodes.

So wipe the base and size from the INITRD config table as soon as it has been consumed. This fixes the issue for kexec on all EFI architectures.

---
 drivers/firmware/efi/efi.c | 1 +
 1 file changed, 1 insertion(+)
drivers/firmware/efi/efi.c +1 -0
index a9070d00b833..988198c36a63 100644
@@ -818,6 +818,7 @@ int __init efi_config_parse_tables(const efi_config_table_t *config_tables,
 		if (tbl) {
 			phys_initrd_start = tbl->base;
 			phys_initrd_size = tbl->size;
+			tbl->base = tbl->size = 0;
 			early_memunmap(tbl, sizeof(*tbl));
 		}
 	}
Signature · 1 line
2.47.3
author maintainer
#1 lore raw
Quoted 31 lines · Ard Biesheuvel

When the EFI stub itself loads the initrd and puts it in memory (rather than simply passing on a struct boot_params or device tree that already carries initrd information), it exposes this information to the core kernel via a INITRD configuration table.

Given that config tables are preserved across kexec, this means that subsequent kexec boots will observe the same information, even though it most likely has become stale by that point. On x86, this information is usually superseded by the initrd info passed via bootparams, in which case this stale information is simply ignored. However, when performing a kexec boot without passing an initrd, the loader falls back to this stale information and explodes.

So wipe the base and size from the INITRD config table as soon as it has been consumed. This fixes the issue for kexec on all EFI architectures.

---
 drivers/firmware/efi/efi.c | 1 +
 1 file changed, 1 insertion(+)
drivers/firmware/efi/efi.c +0 -0
index a9070d00b833..988198c36a63 100644

drivers/firmware/efi/efi.c int __init efi_config_parse_tables(const efi_config_table_t *config_tables, · line 824

Quoted 7 lines
drivers/firmware/efi/efi.c +1 -0
@@ -818,6 +818,7 @@ int __init efi_config_parse_tables(const efi_config_table_t *config_tables,
                if (tbl) {
                        phys_initrd_start = tbl->base;
                        phys_initrd_size = tbl->size;
+                       tbl->base = tbl->size = 0;
                        early_memunmap(tbl, sizeof(*tbl));
                }
        }

I had forgotten about this, I've queued it up now.