Skip to contentSkip to conversation

efi: allow LoadImage from a source buffer

PATCH In review Ahmad Fatoum 2 participants 2 messages Jul 9 – Jul 10

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi: allow LoadImage from a source buffer

LoadImage is allowed to load a PE image from a caller-provided source buffer when no device path is supplied. The SCT covers that path and barebox only handled filesystem-backed images, so valid test images were rejected before StartImage could run them.

Add the source-buffer path and feed it through the normal image loader so the loaded image uses the same validation and bookkeeping as file-backed images.

Assisted-by Codex:gpt-5.5
---
 efi/loader/boot.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
efi/loader/boot.c +9 -4
index b92e6bb33093..d34de119f4e7 100644
@@ -1988,8 +1988,7 @@ efi_status_t EFIAPI efiloader_load_image(bool boot_policy,
 	EFI_ENTRY("%d, %p, %pD, %p, %zu, %p", boot_policy, parent_image,
 		  file_path, source_buffer, source_size, image_handle);
 
-	if (!image_handle || (!source_buffer && !file_path) ||
-	    !efi_search_obj(parent_image) ||
+	if (!image_handle || !efi_search_obj(parent_image) ||
 	    /* The parent image handle must refer to a loaded image */
 	    !parent_image->type) {
 		ret = EFI_INVALID_PARAMETER;
@@ -2005,8 +2004,14 @@ 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);
+	if (file_path) {
+		/* split file_path which contains both the device and file parts */
+		ret = efi_dp_split_file_path(file_path, &dp, &fp);
+	} else {
+		dp = NULL;
+		fp = NULL;
+		ret = EFI_SUCCESS;
+	}
 	if (ret == EFI_SUCCESS) {
 		ret = efi_setup_loaded_image(dp, fp, image_obj, &info);
 		if (ret == EFI_SUCCESS)
Signature · 1 line
2.47.3
#1 lore raw
Quoted 33 lines · Ahmad Fatoum

LoadImage is allowed to load a PE image from a caller-provided source buffer when no device path is supplied. The SCT covers that path and barebox only handled filesystem-backed images, so valid test images were rejected before StartImage could run them.

Add the source-buffer path and feed it through the normal image loader so the loaded image uses the same validation and bookkeeping as file-backed images.

Assisted-by Codex:gpt-5.5
---
 efi/loader/boot.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
efi/loader/boot.c +1 -2
index b92e6bb33093..d34de119f4e7 100644
@@ -1988,8 +1988,7 @@ efi_status_t EFIAPI efiloader_load_image(bool boot_policy,
 	EFI_ENTRY("%d, %p, %pD, %p, %zu, %p", boot_policy, parent_image,
 		  file_path, source_buffer, source_size, image_handle);
 
-	if (!image_handle || (!source_buffer && !file_path) ||
-	    !efi_search_obj(parent_image) ||
+	if (!image_handle || !efi_search_obj(parent_image) ||
 	    /* The parent image handle must refer to a loaded image */
 	    !parent_image->type) {
 		ret = EFI_INVALID_PARAMETER;
@@ -2005,8 +2004,14 @@ efi_status_t EFIAPI efiloader_load_image(bool boot_policy,
 	} else {
 		dest_buffer = source_buffer;
 	}

efi/loader/boot.c efi_status_t EFIAPI efiloader_load_image(bool boot_policy, · line 2014

Quoted 10 lines
efi/loader/boot.c +8 -2
-	/* split file_path which contains both the device and file parts */
-	ret = efi_dp_split_file_path(file_path, &dp, &fp);
+	if (file_path) {
+		/* split file_path which contains both the device and file parts */
+		ret = efi_dp_split_file_path(file_path, &dp, &fp);
+	} else {
+		dp = NULL;
+		fp = NULL;
+		ret = EFI_SUCCESS;
+	}

This hunk doesn't apply on my tree. Can you have a look?

Sascha

--

Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |