From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] efi: loader: accept NULL DevicePath in LoadImage when SourceBuffer is given
Date: Wed, 26 Aug 2026 13:45:01 +0200 [thread overview]
Message-ID: <20260826114521.2919654-1-a.fatoum@pengutronix.de> (raw)
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
next reply other threads:[~2026-08-26 11:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 11:45 Ahmad Fatoum [this message]
2026-08-28 12:14 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260826114521.2919654-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox