[PATCH] efi: loader: accept NULL DevicePath in LoadImage when SourceBuffer is given
Ahmad Fatoum
a.fatoum at pengutronix.de
Wed Aug 26 04:45:01 PDT 2026
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 at 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
More information about the barebox
mailing list