[PATCH 1/2] efi: payload: image: exit if kernel image returned

Ahmad Fatoum a.fatoum at pengutronix.de
Tue Apr 14 07:26:29 PDT 2026


EFI applications can exit and return to the EFI application that started
them and barebox can handle that, except for the case that it was a
EFI-stubbed kernel and barebox has already called shutdown_barebox().

In that case, the safest way is to just propagate the exit code instead
of attempting to execute code as if nothing happened.

Starting EFI applications via bin format continues to work as before.

Cc: Chali Anis <chalianis1 at gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 efi/payload/image.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/efi/payload/image.c b/efi/payload/image.c
index 83094cda6d89..378709b6de95 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -104,7 +104,7 @@ int efi_execute_image(efi_handle_t handle,
 {
 	efi_status_t efiret;
 	const char *options;
-	bool is_driver;
+	bool is_driver, is_kernel = false;
 
 	is_driver = (loaded_image->image_code_type == EFI_BOOT_SERVICES_CODE) ||
 		(loaded_image->image_code_type == EFI_RUNTIME_SERVICES_CODE);
@@ -123,17 +123,24 @@ int efi_execute_image(efi_handle_t handle,
 		efi_set_variable_usec("LoaderTimeExecUSec", &efi_systemd_vendor_guid,
 				      ktime_to_us(ktime_get()));
 
+		is_kernel = true;
 		shutdown_barebox();
 	}
 
 	efi_pause_devices();
 
 	efiret = BS->start_image(handle, NULL, NULL);
-	if (EFI_ERROR(efiret))
-		pr_err("failed to StartImage: %s\n", efi_strerror(efiret));
 
 	efi_continue_devices();
 
+	if (is_kernel) {
+		pr_emerg("Kernel image has unexpectedly returned\n");
+		BS->exit(efi_parent_image, efiret, 0, NULL);
+	}
+
+	if (EFI_ERROR(efiret))
+		pr_err("failed to StartImage: %s\n", efi_strerror(efiret));
+
 	if (!is_driver)
 		BS->unload_image(handle);
 
-- 
2.47.3




More information about the barebox mailing list