Skip to content

Commit e9524fb

Browse files
nivedita76suryasaimadhu
authored andcommitted
efi/x86: Don't blow away existing initrd
Commit 987053a ("efi/x86: Move command-line initrd loading to efi_main") moved the command-line initrd loading into efi_main(), with a check to ensure that it was attempted only if the EFI stub was booted via efi_pe_entry rather than the EFI handover entry. However, in the case where it was booted via handover entry, and thus an initrd may have already been loaded by the bootloader, it then wrote 0 for the initrd address and size, removing any existing initrd. Fix this by checking if size is positive before setting the fields in the bootparams structure. Fixes: 987053a ("efi/x86: Move command-line initrd loading to efi_main") Reported-by: Dan Williams <[email protected]> Signed-off-by: Arvind Sankar <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Ard Biesheuvel <[email protected]> Tested-by: Dan Williams <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent d1343da commit e9524fb

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -768,10 +768,12 @@ unsigned long efi_main(efi_handle_t handle,
768768
efi_err("Failed to load initrd!\n");
769769
goto fail;
770770
}
771-
efi_set_u64_split(addr, &hdr->ramdisk_image,
772-
&boot_params->ext_ramdisk_image);
773-
efi_set_u64_split(size, &hdr->ramdisk_size,
774-
&boot_params->ext_ramdisk_size);
771+
if (size > 0) {
772+
efi_set_u64_split(addr, &hdr->ramdisk_image,
773+
&boot_params->ext_ramdisk_image);
774+
efi_set_u64_split(size, &hdr->ramdisk_size,
775+
&boot_params->ext_ramdisk_size);
776+
}
775777
}
776778

777779
/*

0 commit comments

Comments
 (0)