]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: restore parent loaded image when initrd registration fails
authorLuca Boccassi <luca.boccassi@gmail.com>
Fri, 26 Jun 2026 21:17:28 +0000 (22:17 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 3 Jul 2026 14:19:39 +0000 (15:19 +0100)
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

src/boot/linux.c

index 56b932ecb563ddfd5bf10c4e609267178feea7ec..67ed8599931268730e612cf95533c1df08105fea 100644 (file)
@@ -355,8 +355,12 @@ EFI_STATUS linux_exec(
 
         _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();