Skip to contentSkip to conversation

efi_selftest: fix guid comparison

PATCH Superseded Vincent Stehlé 3 participants 6 messages Jun 11 – Jun 17

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi_selftest: fix guid comparison

The `loaded image' efi selftest is comparing protocol GUIDs with the wrong polarity.
This can be verified on the sandbox, where two protocols GUIDs are retrieved by the test from the image handle in the following order:

1. Loaded Image Device Path Protocol GUID
2. Loaded Image Protocol GUID

The test matches on the first GUID, while it is in fact looking for the second one; fix the comparison polarity.

While at it, use guidcmp() instead of memcmp() to spare the size parameter, and use the Loaded Image Protocol GUID definition from efi_api.h instead or redefining it locally.

Fixes efe79a7c0de0 ("efi_selftest: test for loaded image protocol")
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Tom Rini <[email protected]>
Cc Alexander Graf <[email protected]>
---
 lib/efi_selftest/efi_selftest_loaded_image.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
lib/efi_selftest/efi_selftest_loaded_image.c +2 -5
index 5889ab12617..48890a66db7 100644
@@ -9,9 +9,7 @@
 
 #include <efi_selftest.h>
 
-static efi_guid_t loaded_image_protocol_guid =
-	EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2,
-		 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b);
+static efi_guid_t loaded_image_protocol_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
 static struct efi_boot_services *boottime;
 efi_handle_t image_handle;
 
@@ -60,8 +58,7 @@ static int execute(void)
 	efi_st_printf("%u protocols installed on image handle\n",
 		      (unsigned int)protocol_buffer_count);
 	for (i = 0; i < protocol_buffer_count; ++i) {
-		if (memcmp(protocol_buffer[i], &loaded_image_protocol_guid,
-			   sizeof(efi_guid_t)))
+		if (!guidcmp(protocol_buffer[i], &loaded_image_protocol_guid))
 			found = true;
 	}
 	if (!found) {
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Vincent Stehlé

The `loaded image' efi selftest is comparing protocol GUIDs with the wrong polarity.
This can be verified on the sandbox, where two protocols GUIDs are retrieved by the test from the image handle in the following order:

1. Loaded Image Device Path Protocol GUID
2. Loaded Image Protocol GUID

The test matches on the first GUID, while it is in fact looking for the second one; fix the comparison polarity.

While at it, use guidcmp() instead of memcmp() to spare the size parameter, and use the Loaded Image Protocol GUID definition from efi_api.h instead or redefining it locally.

Quoted 7 lines
Fixes efe79a7c0de0 ("efi_selftest: test for loaded image protocol")
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Tom Rini <[email protected]>
Cc Alexander Graf <[email protected]>

---

Quoted 31 lines
 lib/efi_selftest/efi_selftest_loaded_image.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
lib/efi_selftest/efi_selftest_loaded_image.c +2 -6
index 5889ab12617..48890a66db7 100644
@@ -9,9 +9,7 @@
 
 #include <efi_selftest.h>
 
-static efi_guid_t loaded_image_protocol_guid =
-       EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2,
-                0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b);
+static efi_guid_t loaded_image_protocol_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
 static struct efi_boot_services *boottime;
 efi_handle_t image_handle;
 
@@ -60,8 +58,7 @@ static int execute(void)
        efi_st_printf("%u protocols installed on image handle\n",
                      (unsigned int)protocol_buffer_count);
        for (i = 0; i < protocol_buffer_count; ++i) {
-               if (memcmp(protocol_buffer[i], &loaded_image_protocol_guid,
-                          sizeof(efi_guid_t)))
+               if (!guidcmp(protocol_buffer[i], &loaded_image_protocol_guid))
                        found = true;
        }
        if (!found) {
--

2.53.0

#2 lore raw
In reply to Vincent Stehlé
Quoted 8 lines · Vincent Stehlé

The `loaded image' efi selftest is comparing protocol GUIDs with the wrong polarity.
This can be verified on the sandbox, where two protocols GUIDs are retrieved by the test from the image handle in the following order:

1. Loaded Image Device Path Protocol GUID
2. Loaded Image Protocol GUID

Quoted 6 lines

The test matches on the first GUID, while it is in fact looking for the second one; fix the comparison polarity.

While at it, use guidcmp() instead of memcmp() to spare the size parameter, and use the Loaded Image Protocol GUID definition from efi_api.h instead or redefining it locally.

Hello Vincent,

Thank you for catching the issue with the incorrect checkout for the Loaded Image Protocol.

We never use U-Boot library functions in efi_selftest to allow converting it into a standalone EFI application.

Quoted 16 lines
Fixes efe79a7c0de0 ("efi_selftest: test for loaded image protocol")
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Tom Rini <[email protected]>
Cc Alexander Graf <[email protected]>
---
  lib/efi_selftest/efi_selftest_loaded_image.c | 7 ++-----
  1 file changed, 2 insertions(+), 5 deletions(-)
lib/efi_selftest/efi_selftest_loaded_image.c +0 -0
index 5889ab12617..48890a66db7 100644

lib/efi_selftest/efi_selftest_loaded_image.c line 12

Quoted 7 lines
lib/efi_selftest/efi_selftest_loaded_image.c +1 -3
@@ -9,9 +9,7 @@
 
  #include <efi_selftest.h>
 
-static efi_guid_t loaded_image_protocol_guid =
-	EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2,
-		 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b);
+static efi_guid_t loaded_image_protocol_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;

This change is not described in the commit message. With the change we no longer test if efi_api.h has the correct value of the GUID. Why would you prefer this?

lib/efi_selftest/efi_selftest_loaded_image.c static int execute(void) · line 62

Quoted 11 lines
lib/efi_selftest/efi_selftest_loaded_image.c +1 -2
  static struct efi_boot_services *boottime;
  efi_handle_t image_handle;
 
@@ -60,8 +58,7 @@ static int execute(void)
  	efi_st_printf("%u protocols installed on image handle\n",
  		      (unsigned int)protocol_buffer_count);
  	for (i = 0; i < protocol_buffer_count; ++i) {
-		if (memcmp(protocol_buffer[i], &loaded_image_protocol_guid,
-			   sizeof(efi_guid_t)))
+		if (!guidcmp(protocol_buffer[i], &loaded_image_protocol_guid))
  			found = true;

Changing the polarity is correct.

Best regards

Heinrich

Quoted 2 lines
lib/efi_selftest/efi_selftest_loaded_image.c +0 -0
  	}
  	if (!found) {
#3 lore raw
Quoted 12 lines · Heinrich Schuchardt
Quoted 11 lines · Vincent Stehlé

The `loaded image' efi selftest is comparing protocol GUIDs with the wrong polarity.
This can be verified on the sandbox, where two protocols GUIDs are retrieved by the test from the image handle in the following order:

1. Loaded Image Device Path Protocol GUID
2. Loaded Image Protocol GUID

The test matches on the first GUID, while it is in fact looking for the second one; fix the comparison polarity.

Quoted 8 lines
Quoted 3 lines

While at it, use guidcmp() instead of memcmp() to spare the size parameter, and use the Loaded Image Protocol GUID definition from efi_api.h instead or redefining it locally.

Hello Vincent,

Thank you for catching the issue with the incorrect checkout for the Loaded Image Protocol.

Hi Heinrich,

Thanks for your review.

Quoted 2 lines

We never use U-Boot library functions in efi_selftest to allow converting it into a standalone EFI application.

Ok, this makes sense.
I will send a v2 keeping memcmp().

Note that I see 4 calls to guidcmp() in the selftests already. I think this does not harm in practice because guidcmp() this is marked inline.
I also see more than a dozen places where memcmp() is used to compare GUIDs in the selftests.

Would you like me to send another series to add a local definition of guidcmp() for the selftests and convert all memcmp() when appropriate?
Or should I rather send a series converting all uses of guidcmp() in the selftests to memcmp(), maybe?

Quoted 12 lines
Quoted 12 lines
Fixes efe79a7c0de0 ("efi_selftest: test for loaded image protocol")
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Tom Rini <[email protected]>
Cc Alexander Graf <[email protected]>
---
  lib/efi_selftest/efi_selftest_loaded_image.c | 7 ++-----
  1 file changed, 2 insertions(+), 5 deletions(-)
Quoted 12 lines

lib/efi_selftest/efi_selftest_loaded_image.c line 10

Quoted 10 lines
lib/efi_selftest/efi_selftest_loaded_image.c +1 -3
index 5889ab12617..48890a66db7 100644
@@ -9,9 +9,7 @@
  #include <efi_selftest.h>
-static efi_guid_t loaded_image_protocol_guid =
-	EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2,
-		 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b);
+static efi_guid_t loaded_image_protocol_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;

This change is not described in the commit message.

It was a bit hidden, but it was mentioned:

(..) and use the Loaded Image Protocol GUID definition from efi_api.h instead or redefining it locally.

Quoted 3 lines

With the change we no
longer test if efi_api.h has the correct value of the GUID. Why would you prefer this?

Sure, it could make sense to duplicate the GUIDs definitions for test purposes. I will keep the definition as it is in the v2.

Note that we have a dozen places in the selftests using the common GUID definitions from efi_api.h; shall I send a patch series to replace those?

Best regards,
Vincent.

Quoted 20 lines

lib/efi_selftest/efi_selftest_loaded_image.c static int execute(void) · line 62

Quoted 11 lines
lib/efi_selftest/efi_selftest_loaded_image.c +1 -2
  static struct efi_boot_services *boottime;
  efi_handle_t image_handle;
@@ -60,8 +58,7 @@ static int execute(void)
  	efi_st_printf("%u protocols installed on image handle\n",
  		      (unsigned int)protocol_buffer_count);
  	for (i = 0; i < protocol_buffer_count; ++i) {
-		if (memcmp(protocol_buffer[i], &loaded_image_protocol_guid,
-			   sizeof(efi_guid_t)))
+		if (!guidcmp(protocol_buffer[i], &loaded_image_protocol_guid))
  			found = true;

Changing the polarity is correct.

Best regards

Heinrich

Quoted 2 lines
lib/efi_selftest/efi_selftest_loaded_image.c +0 -0
  	}
  	if (!found) {
Signature · 1 line
Vincent.
#4 lore raw

PATCH v2 1/1 efi_selftest: fix guid comparison

In reply to Vincent Stehlé

The `loaded image' efi selftest is comparing protocol GUIDs with the wrong polarity.
This can be verified on the sandbox, where two protocols GUIDs are retrieved by the test from the image handle in the following order:

1. Loaded Image Device Path Protocol GUID
2. Loaded Image Protocol GUID

The test matches on the first GUID, while it is in fact looking for the second one; fix the comparison polarity.

Fixes efe79a7c0de0 ("efi_selftest: test for loaded image protocol")
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Tom Rini <[email protected]>
Cc Alexander Graf <[email protected]>

---

Changes for v2:
- Continue using memcmp() and not guidcmp()
- Keep the Loaded Image Protocol GUID definition
- Fix Alexander's e-mail address

 lib/efi_selftest/efi_selftest_loaded_image.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/efi_selftest/efi_selftest_loaded_image.c +2 -2
index 5889ab12617..e0668f60ebd 100644
@@ -60,8 +60,8 @@ static int execute(void)
 	efi_st_printf("%u protocols installed on image handle\n",
 		      (unsigned int)protocol_buffer_count);
 	for (i = 0; i < protocol_buffer_count; ++i) {
-		if (memcmp(protocol_buffer[i], &loaded_image_protocol_guid,
-			   sizeof(efi_guid_t)))
+		if (!memcmp(protocol_buffer[i], &loaded_image_protocol_guid,
+			    sizeof(efi_guid_t)))
 			found = true;
 	}
 	if (!found) {
Signature · 1 line
2.53.0
Reviewed-by on v2 1/1
#5 lore raw

Am 15. Juni 2026 12:56:15 MESZ schrieb "Vincent Stehlé" <[email protected]>:

Quoted 11 lines

The `loaded image' efi selftest is comparing protocol GUIDs with the wrong polarity.
This can be verified on the sandbox, where two protocols GUIDs are retrieved by the test from the image handle in the following order:

1. Loaded Image Device Path Protocol GUID
2. Loaded Image Protocol GUID

The test matches on the first GUID, while it is in fact looking for the second one; fix the comparison polarity.

Quoted 6 lines
Fixes efe79a7c0de0 ("efi_selftest: test for loaded image protocol")
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Tom Rini <[email protected]>
Cc Alexander Graf <[email protected]>
Quoted 25 lines

---

Changes for v2:
- Continue using memcmp() and not guidcmp()
- Keep the Loaded Image Protocol GUID definition
- Fix Alexander's e-mail address

lib/efi_selftest/efi_selftest_loaded_image.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
lib/efi_selftest/efi_selftest_loaded_image.c +2 -2
index 5889ab12617..e0668f60ebd 100644
@@ -60,8 +60,8 @@ static int execute(void)
 	efi_st_printf("%u protocols installed on image handle\n",
 		      (unsigned int)protocol_buffer_count);
 	for (i = 0; i < protocol_buffer_count; ++i) {
-		if (memcmp(protocol_buffer[i], &loaded_image_protocol_guid,
-			   sizeof(efi_guid_t)))
+		if (!memcmp(protocol_buffer[i], &loaded_image_protocol_guid,
+			    sizeof(efi_guid_t)))
 			found = true;
 	}
 	if (!found) {