mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] efi: loader: accept NULL DevicePath in LoadImage when SourceBuffer is given
@ 2026-08-26 11:45 Ahmad Fatoum
  2026-08-28 12:14 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2026-08-26 11:45 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The UEFI specification only requires DevicePath when no SourceBuffer is
given. Loading an image from memory with a NULL DevicePath is valid and
results in a loaded image without device handle and file path. That's what
EDK2 does and what the U-Boot code this was imported from does as well, as
it ignores the result of efi_dp_split_file_path().

barebox on the other hand checks the result and as efi_dp_dup(NULL) returns
NULL, LoadImage fails with the misleading EFI_OUT_OF_RESOURCES. This breaks
chainloading from a barebox EFI payload running on top of the barebox EFI
loader: the payload passes the device path of its own device handle, which
it doesn't have when it was booted via QEMU's fw_cfg, so it passes NULL.

Only split the device path if there is one and hand out an empty file path
otherwise, so LoadedImage->FilePath stays non-NULL for applications like
the EDK2 shell that dereference it unconditionally.

Fixes: b9e581c97389 ("efi: loader: avoid NULL image file paths")
Assisted-by: Claude:fable-5
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 efi/loader/boot.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/efi/loader/boot.c b/efi/loader/boot.c
index d361a71a4dae..2d98c95b5c34 100644
--- a/efi/loader/boot.c
+++ b/efi/loader/boot.c
@@ -2026,8 +2026,18 @@ efi_status_t EFIAPI efiloader_load_image(bool boot_policy,
 	} else {
 		dest_buffer = source_buffer;
 	}
-	/* split file_path which contains both the device and file parts */
-	ret = efi_dp_split_file_path(file_path, &dp, &fp);
+	/*
+	 * DevicePath is optional when SourceBuffer is given, the loaded image
+	 * then has no device handle and an empty file path.
+	 */
+	if (file_path) {
+		/* file_path contains both the device and the file parts */
+		ret = efi_dp_split_file_path(file_path, &dp, &fp);
+	} else {
+		dp = NULL;
+		fp = efi_dp_append_node(NULL, NULL);
+		ret = fp ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES;
+	}
 	if (ret == EFI_SUCCESS) {
 		ret = efi_setup_loaded_image(dp, fp, image_obj, &info);
 		if (ret == EFI_SUCCESS)
-- 
2.47.3




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-28 12:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-26 11:45 [PATCH] efi: loader: accept NULL DevicePath in LoadImage when SourceBuffer is given Ahmad Fatoum
2026-08-28 12:14 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox