Skip to contentSkip to conversation

efi: test and fix specific LoadImage() return code

PATCH New Vincent Stehlé 1 participant 3 messages Feb 16

lore
Share & tools
lore
#0 lore raw

cover efi: test and fix specific LoadImage() return code

Hi,

This couple of patches addresses a specific case of LoadImage(), which is now tested by the SCT [311] and has been sent to me by Sathisha (thanks!)

The first patch fixes the specific return code and the second patch adds a unit test for this specific case; we do this in that order to avoid breaking the efi self test.

Best regards,
Vincent.

[311] https://github.com/tianocore/edk2-test/issues/311

Vincent Stehlé (2):
efi_loader: fix specific LoadImage() return code
efi_selftest: test specific LoadImage() case

 lib/efi_loader/efi_boottime.c             | 8 ++++++--
 lib/efi_selftest/efi_selftest_loadimage.c | 7 +++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH 1/2 efi_loader: fix specific LoadImage() return code

When the LoadImage() UEFI function is called with both its SourceBuffer and DevicePath input arguments equal to NULL, it must return EFI_NOT_FOUND [1]. However, it does return EFI_INVALID_PARAMETER instead; fix it.

---
 lib/efi_loader/efi_boottime.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
lib/efi_loader/efi_boottime.c +6 -2
index b424d924896..de57823bd44 100644
@@ -2096,8 +2096,12 @@ efi_status_t EFIAPI efi_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 (!source_buffer && !file_path) {
+		ret = EFI_NOT_FOUND;
+		goto error;
+	}
+
+	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;
Signature · 1 line
2.51.0
#2 lore raw

PATCH 2/2 efi_selftest: test specific LoadImage() case

In reply to Vincent Stehlé

Add a test calling the LoadImage() UEFI function with both its SourceBuffer and DevicePath input arguments equal to NULL.

This test can be run on the sandbox with the following command:

  ./u-boot -T -c "setenv efi_selftest load image from file; \
                  bootefi selftest"
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Tom Rini <[email protected]>
---
 lib/efi_selftest/efi_selftest_loadimage.c | 7 +++++++
 1 file changed, 7 insertions(+)
lib/efi_selftest/efi_selftest_loadimage.c +7 -0
index 967eaa58c69..0e8fc6216f0 100644
@@ -562,6 +562,13 @@ static int execute(void)
 		return EFI_ST_FAILURE;
 	}
 
+	ret = boottime->load_image(false, handle_image, NULL, NULL, 0,
+				   &handle);
+	if (ret != EFI_NOT_FOUND) {
+		efi_st_error("Unexpected load_image return value\n");
+		return EFI_ST_FAILURE;
+	}
+
 	return EFI_ST_SUCCESS;
 }
 
Signature · 1 line
2.51.0