linux_exec() patches the stub's own EFI_LOADED_IMAGE_PROTOCOL to point
at the loaded inner kernel, and restores the saved original only after
the entry point returns. The initrd_register() failure path returns
without restoring, leaving the firmware's protocol pointing to freed
data.
Follow-up for
f4051650657cd337ceba67b773f0e3bf854cbaff
_cleanup_(cleanup_initrd) EFI_HANDLE initrd_handle = NULL;
err = initrd_register(initrd, &initrd_handle);
- if (err != EFI_SUCCESS)
+ if (err != EFI_SUCCESS) {
+ /* Restore the patched fields before kernel_file_path and loaded_kernel_pages are freed,
+ * otherwise the stub's own EFI_LOADED_IMAGE_PROTOCOL is left pointing at freed memory. */
+ *parent_loaded_image = original_parent_loaded_image;
return log_error_status(err, "Error registering initrd: %m");
+ }
log_wait();