Skip to contentSkip to conversation

efi: fix and test FMP image info authentication attribute

PATCH Superseded Vincent Stehlé 5 participants 17 messages Sep 22 – Oct 8

lore
Share & tools
lore
#0 lore raw

cover efi: fix and test FMP image info authentication attribute

Here is a couple of patches to:

- Do a small fix in the UEFI Firmware Management Protocol:
GetImageInfo() returns a correct authentication flag for the first image, but not for the subsequent ones.

- Add a minimal FMP selftest, just enough to catch this issue, and which should be easy enough to extend in the future.

---
Vincent Stehlé (2):
efi_loader: fix image info authentication attribute
efi_selftest: add minimal fmp test

 lib/efi_loader/efi_firmware.c       |   2 +-
 lib/efi_selftest/Makefile           |   2 +
 lib/efi_selftest/efi_selftest_fmp.c | 135 ++++++++++++++++++++++++++++++++++++
 3 files changed, 138 insertions(+), 1 deletion(-)

---
base-commit: a06e89ab05eaa2b8344d521319399333cd760ae5
change-id: 20260922-authi-329cc6a9a07c

Best regards,

Signature · 1 line
Vincent.
#1 lore raw

PATCH 1/2 efi_loader: fix image info authentication attribute

The GetImageInfo() function of the UEFI Firmware Management Protocol returns the authentication required attribute correctly in AttributesSetting only for the first image; fix this.

Fixes 88a2ef2720f5 ("efi_loader: Enable uefi capsule authentication")
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Tom Rini <[email protected]>
Cc Sughosh Ganu <[email protected]>
---
 lib/efi_loader/efi_firmware.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/efi_loader/efi_firmware.c +1 -1
index b41969c70fd..84de95f5c23 100644
@@ -364,7 +364,7 @@ static efi_status_t efi_fill_image_desc_array(
 
 		/* Check if the capsule authentication is enabled */
 		if (IS_ENABLED(CONFIG_EFI_CAPSULE_AUTHENTICATE))
-			image_info[0].attributes_setting |=
+			image_info[i].attributes_setting |=
 				IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED;
 
 		image_info[i].hardware_instance = 1;
Signature · 1 line
2.53.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] efi_loader: fix image info authentication attribute

Quoted 13 lines · Vincent Stehlé

efi_loader: fix image info authentication attribute

The GetImageInfo() function of the UEFI Firmware Management Protocol returns the authentication required attribute correctly in AttributesSetting only for the first image; fix this.

Fixes 88a2ef2720f5 ("efi_loader: Enable uefi capsule authentication")
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Tom Rini <[email protected]>
Cc Sughosh Ganu <[email protected]>
Quoted 2 lines

lib/efi_loader/efi_firmware.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] efi_loader: fix image info authentication attribute

In reply to Vincent Stehlé
Quoted 5 lines · Vincent Stehlé

The GetImageInfo() function of the UEFI Firmware Management Protocol returns the authentication required attribute correctly in AttributesSetting only for the first image; fix this.

Quoted 7 lines
Fixes 88a2ef2720f5 ("efi_loader: Enable uefi capsule authentication")
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Tom Rini <[email protected]>
Cc Sughosh Ganu <[email protected]>

---

Quoted 20 lines
 lib/efi_loader/efi_firmware.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/efi_loader/efi_firmware.c +1 -2
index b41969c70fd..84de95f5c23 100644
@@ -364,7 +364,7 @@ static efi_status_t efi_fill_image_desc_array(
 
                /* Check if the capsule authentication is enabled */
                if (IS_ENABLED(CONFIG_EFI_CAPSULE_AUTHENTICATE))
-                       image_info[0].attributes_setting |=
+                       image_info[i].attributes_setting |=
                                IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED;
 
                image_info[i].hardware_instance = 1;
 
--

2.53.0

#4 lore raw

PATCH 2/2 efi_selftest: add minimal fmp test

In reply to Vincent Stehlé

Add a minimal test for the UEFI Firmware Management Protocol. At this point the test only does the following:

- Get current firmware images info.
- For each image, verify consistency of the authentication flags.

This can be tested on the sandbox with the following command:

  ./u-boot -T -c "setenv efi_selftest firmware management protocol; \
                  bootefi selftest"
Cc Tom Rini <[email protected]>
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
---
 lib/efi_selftest/Makefile           |   2 +
 lib/efi_selftest/efi_selftest_fmp.c | 135 ++++++++++++++++++++++++++++++++++++
 2 files changed, 137 insertions(+)
lib/efi_selftest/Makefile +2 -0
index 67102648703..9882d9f2748 100644
@@ -80,6 +80,8 @@ obj-$(CONFIG_EFI_ESRT) += efi_selftest_esrt.o
 
 obj-$(CONFIG_EFI_DEBUG_SUPPORT) += efi_selftest_debug_support.o
 
+obj-$(CONFIG_EFI_CAPSULE_FIRMWARE) += efi_selftest_fmp.o
+
 targets += \
 efi_miniapp_file_image_exception.h \
 efi_miniapp_file_image_exit.h \
lib/efi_selftest/efi_selftest_fmp.c new file +135 -0

135 lines not on this page · raw message

Signature · 1 line
2.53.0
#5 lore raw

Re: [PATCH 2/2] efi_selftest: add minimal fmp test

Hi Vincent,

Quoted 24 lines · Vincent Stehlé

efi_selftest: add minimal fmp test

Add a minimal test for the UEFI Firmware Management Protocol. At this point the test only does the following:

- Get current firmware images info.
- For each image, verify consistency of the authentication flags.

This can be tested on the sandbox with the following command:

  ./u-boot -T -c "setenv efi_selftest firmware management protocol; \
                  bootefi selftest"
Cc Tom Rini <[email protected]>
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>

lib/efi_selftest/Makefile | 2 +

 lib/efi_selftest/efi_selftest_fmp.c | 135 ++++++++++++++++++++++++++++++++++++
 2 files changed, 137 insertions(+)

lib/efi_selftest/efi_selftest_fmp.c line 3

Quoted 3 lines
lib/efi_selftest/efi_selftest_fmp.c +3 -0
@@ -0,0 +1,135 @@
+     /* Verify each image info */
+     for (i = 0; i < desc_cnt; i++) {
+             const struct efi_firmware_image_descriptor *inf = &img_info[i];

The spec says callers must step through the array using DescriptorSize, since firmware may return a larger (newer) descriptor than the one we know about. U-Boot happens to use sizeof(), but since this is a protocol test, please can you use desc_size as the stride, e.g. (void *)img_info + i * desc_size, and perhaps check that desc_size >= sizeof(*inf)?

lib/efi_selftest/efi_selftest_fmp.c line 8

Quoted 10 lines
lib/efi_selftest/efi_selftest_fmp.c +8 -0
@@ -0,0 +1,135 @@
+             /* Verify authentication */
+             if (CONFIG_IS_ENABLED(EFI_CAPSULE_AUTHENTICATE) &&
+                 (attr_supp & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE) &&
+                 !(attr_supp & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED)) {
+                     efi_st_error("Bad AttributesSupported %u\n",
+                                  (unsigned int)attr_supp);
+                     goto out;
+             }

efi_firmware.c uses IS_ENABLED(CONFIG_EFI_CAPSULE_AUTHENTICATE), so please match that. There is no SPL variant of this option, so CONFIG_IS_ENABLED() just adds confusion.

This only checks one direction. You could also check that any bit set in AttributesSetting is also set in AttributesSupported, and that AUTHENTICATION_REQUIRED is not set in AttributesSetting when authentication is disabled. That would also catch regressions on boards without CONFIG_EFI_CAPSULE_AUTHENTICATE. What do you think?

lib/efi_selftest/efi_selftest_fmp.c line 2

Quoted 4 lines
lib/efi_selftest/efi_selftest_fmp.c +2 -0
@@ -0,0 +1,135 @@
+     ret = boottime->locate_protocol(&firmware_management_protocol_guid,
+                                     NULL, (void **)&fmp);

This only tests the first FMP instance. With CONFIG_EFI_CAPSULE_FIRMWARE_FIT and _RAW both enabled on sandbox there can be two, so using locate_handle_buffer() and checking each one would make the test more useful as it grows. I'm fine with leaving that for later though, since the patch says 'minimal'.

Regards,
Simon

#6 lore raw

Re: [PATCH 2/2] efi_selftest: add minimal fmp test

Quoted 1 line · Simon Glass

Hi Vincent,

Hi Simon,

Thank you very much for your review.
I will send a v2 addressing all your remarks.

Best regards,
Vincent.

Quoted 71 lines · Vincent Stehlé
Quoted 24 lines

efi_selftest: add minimal fmp test

Add a minimal test for the UEFI Firmware Management Protocol. At this point the test only does the following:

- Get current firmware images info.
- For each image, verify consistency of the authentication flags.

This can be tested on the sandbox with the following command:

  ./u-boot -T -c "setenv efi_selftest firmware management protocol; \
                  bootefi selftest"
Cc Tom Rini <[email protected]>
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>

lib/efi_selftest/Makefile | 2 +

 lib/efi_selftest/efi_selftest_fmp.c | 135 ++++++++++++++++++++++++++++++++++++
 2 files changed, 137 insertions(+)

lib/efi_selftest/efi_selftest_fmp.c line 3

Quoted 3 lines
lib/efi_selftest/efi_selftest_fmp.c +3 -0
@@ -0,0 +1,135 @@
+     /* Verify each image info */
+     for (i = 0; i < desc_cnt; i++) {
+             const struct efi_firmware_image_descriptor *inf = &img_info[i];

The spec says callers must step through the array using DescriptorSize, since firmware may return a larger (newer) descriptor than the one we know about. U-Boot happens to use sizeof(), but since this is a protocol test, please can you use desc_size as the stride, e.g. (void *)img_info + i * desc_size, and perhaps check that desc_size >= sizeof(*inf)?

lib/efi_selftest/efi_selftest_fmp.c line 8

Quoted 10 lines
lib/efi_selftest/efi_selftest_fmp.c +8 -0
@@ -0,0 +1,135 @@
+             /* Verify authentication */
+             if (CONFIG_IS_ENABLED(EFI_CAPSULE_AUTHENTICATE) &&
+                 (attr_supp & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE) &&
+                 !(attr_supp & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED)) {
+                     efi_st_error("Bad AttributesSupported %u\n",
+                                  (unsigned int)attr_supp);
+                     goto out;
+             }

efi_firmware.c uses IS_ENABLED(CONFIG_EFI_CAPSULE_AUTHENTICATE), so please match that. There is no SPL variant of this option, so CONFIG_IS_ENABLED() just adds confusion.

This only checks one direction. You could also check that any bit set in AttributesSetting is also set in AttributesSupported, and that AUTHENTICATION_REQUIRED is not set in AttributesSetting when authentication is disabled. That would also catch regressions on boards without CONFIG_EFI_CAPSULE_AUTHENTICATE. What do you think?

lib/efi_selftest/efi_selftest_fmp.c line 2

Quoted 4 lines
lib/efi_selftest/efi_selftest_fmp.c +2 -0
@@ -0,0 +1,135 @@
+     ret = boottime->locate_protocol(&firmware_management_protocol_guid,
+                                     NULL, (void **)&fmp);

This only tests the first FMP instance. With CONFIG_EFI_CAPSULE_FIRMWARE_FIT and _RAW both enabled on sandbox there can be two, so using locate_handle_buffer() and checking each one would make the test more useful as it grows. I'm fine with leaving that for later though, since the patch says 'minimal'.

Regards,
Simon

#7 lore raw

Re: [PATCH 2/2] efi_selftest: add minimal fmp test

In reply to Vincent Stehlé
Quoted 95 lines · Vincent Stehlé

Add a minimal test for the UEFI Firmware Management Protocol. At this point the test only does the following:

- Get current firmware images info.
- For each image, verify consistency of the authentication flags.

This can be tested on the sandbox with the following command:

   ./u-boot -T -c "setenv efi_selftest firmware management protocol; \
                   bootefi selftest"
Cc Tom Rini <[email protected]>
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
---
  lib/efi_selftest/Makefile           |   2 +
  lib/efi_selftest/efi_selftest_fmp.c | 135 ++++++++++++++++++++++++++++++++++++
  2 files changed, 137 insertions(+)
lib/efi_selftest/Makefile +2 -0
index 67102648703..9882d9f2748 100644
@@ -80,6 +80,8 @@ obj-$(CONFIG_EFI_ESRT) += efi_selftest_esrt.o
 
  obj-$(CONFIG_EFI_DEBUG_SUPPORT) += efi_selftest_debug_support.o
 
+obj-$(CONFIG_EFI_CAPSULE_FIRMWARE) += efi_selftest_fmp.o
+
  targets += \
  efi_miniapp_file_image_exception.h \
  efi_miniapp_file_image_exit.h \
lib/efi_selftest/efi_selftest_fmp.c new file +56 -0
new file mode 100644
index 00000000000..c17cf59a237
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Test Firmware Management Protocol support.
+ *
+ * Copyright (C) 2026 Arm Ltd.
+ */
+#include <efi_selftest.h>
+
+static const efi_guid_t firmware_management_protocol_guid =
+	EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID;
+
+static struct efi_boot_services *boottime;
+static struct efi_firmware_management_protocol *fmp;
+
+/**
+ * setup() - Setup unit test.
+ * @handle:	handle of the loaded image
+ * @systable:	system table
+ *
+ * Keep Boot Services and locate firmware management protocol.
+ *
+ * Return:	EFI_ST_SUCCESS for success, EFI_ST_FAILURE in case of error.
+ */
+static int setup(const efi_handle_t handle,
+		 const struct efi_system_table *systable)
+{
+	efi_status_t ret;
+
+	boottime = systable->boottime;
+
+	ret = boottime->locate_protocol(&firmware_management_protocol_guid,
+					NULL, (void **)&fmp);
+	if (ret != EFI_SUCCESS) {
+		efi_st_error("Firmware management protocol not available.\n");
+		return EFI_ST_FAILURE;
+	}
+
+	return EFI_ST_SUCCESS;
+}
+
+/**
+ * execute() - Perform the test.
+ *
+ * Call GetImageInfo() to retrieve current firmware images descriptors.
+ * For each descriptor, verify image authentication consistency.
+ *
+ * Return:	EFI_ST_SUCCESS for success, EFI_ST_FAILURE in case of error.
+ */
+static int execute(void)
+{
+	efi_status_t ret;
+	efi_uintn_t img_info_size, desc_size;
+	struct efi_firmware_image_descriptor *img_info = NULL;
+	u32 desc_ver, pkg_ver;
+	u8 desc_cnt;
+	u16 *pkg_ver_name;

lib/efi_selftest/efi_selftest_fmp.c line 66

Quoted 10 lines
lib/efi_selftest/efi_selftest_fmp.c new file +10 -0
+	int i, result = EFI_ST_FAILURE;
+
+	/* Determine buffer size */
+	img_info_size = 0;
+	ret = fmp->get_image_info(fmp, &img_info_size, NULL, NULL, NULL, NULL,
+				  NULL, NULL);
+	if (ret != EFI_BUFFER_TOO_SMALL) {
+		efi_st_error("GetImageInfo returned %u\n", (unsigned int)ret);
+		goto out;
+	}

This fails if the number of images is 0.

ERROR: GetImageInfo returned 2 (EFI_INVALID_PARAMETER)

+struct efi_fw_image fw_images[] = {
+};
+
+struct efi_capsule_update_info update_info = {

+       .dfu_string = NULL,
+       .num_images = ARRAY_SIZE(fw_images),
+       .images = fw_images,

+};

This looks like a bug in efi_fill_image_desc_array((). Why does it return EFI_INVALID_PARAMETER if the number of images is 0?

We should just return *img_info_size = 0 and EFI_SUCCESS instead.

The test should return EFI_ST_SUCCESS in this case.

Best regards

Heinrich

Quoted 70 lines
lib/efi_selftest/efi_selftest_fmp.c new file +69 -0
+
+	/* Allocate enough memory for image info */
+	ret = boottime->allocate_pool(EFI_LOADER_DATA, img_info_size,
+				      (void **)&img_info);
+	if (ret != EFI_SUCCESS) {
+		efi_st_error("AllocatePool returned %u\n", (unsigned int)ret);
+		goto out;
+	}
+
+	ret = fmp->get_image_info(fmp, &img_info_size, img_info, &desc_ver,
+				  &desc_cnt, &desc_size, &pkg_ver,
+				  &pkg_ver_name);
+	if (ret != EFI_SUCCESS) {
+		efi_st_error("GetImageInfo returned %u\n", (unsigned int)ret);
+		goto out;
+	}
+
+	if (desc_ver != EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION) {
+		efi_st_error("Bad DescriptorVersion %u\n", desc_ver);
+		goto out;
+	}
+
+	/* Verify each image info */
+	for (i = 0; i < desc_cnt; i++) {
+		const struct efi_firmware_image_descriptor *inf = &img_info[i];
+		u64 attr_supp = inf->attributes_supported,
+		    attr_set = inf->attributes_setting;
+
+		efi_st_printf("  image %u: %ps\n", inf->image_index, inf->image_id_name);
+
+		/* Verify authentication */
+		if (CONFIG_IS_ENABLED(EFI_CAPSULE_AUTHENTICATE) &&
+		    (attr_supp & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE) &&
+		    !(attr_supp & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED)) {
+			efi_st_error("Bad AttributesSupported %u\n",
+				     (unsigned int)attr_supp);
+			goto out;
+		}
+
+		if (CONFIG_IS_ENABLED(EFI_CAPSULE_AUTHENTICATE) &&
+		    (attr_set & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE) &&
+		    !(attr_set & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED)) {
+			efi_st_error("Bad AttributesSetting %u\n",
+				     (unsigned int)attr_set);
+			goto out;
+		}
+	}
+
+	result = EFI_ST_SUCCESS;
+
+out:
+	if (img_info) {
+		ret = boottime->free_pool(img_info);
+		if (ret != EFI_SUCCESS) {
+			efi_st_error("FreePool returned %u\n",
+				     (unsigned int)ret);
+			result = EFI_ST_FAILURE;
+		}
+	}
+
+	return result;
+}
+
+EFI_UNIT_TEST(fmp) = {
+	.name = "firmware management protocol",
+	.phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
+	.setup = setup,
+	.execute = execute,
+};
#8 lore raw

Re: [PATCH 2/2] efi_selftest: add minimal fmp test

Quoted 2 lines · Heinrich Schuchardt
Quoted 1 line · Vincent Stehlé

Add a minimal test for the UEFI Firmware Management Protocol.

(..)

Quoted 22 lines

lib/efi_selftest/efi_selftest_fmp.c line 66

Quoted 8 lines
lib/efi_selftest/efi_selftest_fmp.c new file +8 -0
+	/* Determine buffer size */
+	img_info_size = 0;
+	ret = fmp->get_image_info(fmp, &img_info_size, NULL, NULL, NULL, NULL,
+				  NULL, NULL);
+	if (ret != EFI_BUFFER_TOO_SMALL) {
+		efi_st_error("GetImageInfo returned %u\n", (unsigned int)ret);
+		goto out;
+	}

This fails if the number of images is 0.

ERROR: GetImageInfo returned 2 (EFI_INVALID_PARAMETER)

(quoted diff) +8 -0
+struct efi_fw_image fw_images[] = {
+};
+
+struct efi_capsule_update_info update_info = {
+       .dfu_string = NULL,
+       .num_images = ARRAY_SIZE(fw_images),
+       .images = fw_images,
+};
Quoted 6 lines

This looks like a bug in efi_fill_image_desc_array((). Why does it return EFI_INVALID_PARAMETER if the number of images is 0?

We should just return *img_info_size = 0 and EFI_SUCCESS instead.

The test should return EFI_ST_SUCCESS in this case.

Hi Heinrich,

Thank you very much for reviewing.

I confirm that I could reproduce this corner case with your changes.

In the end I think the test (v2) itself is fine, as it does pass when I replace the calls to get_image_info() by the following code:

+       img_info = NULL;
+       desc_ver = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION;
+       desc_cnt = 0;
+       desc_size = sizeof(struct efi_firmware_image_descriptor);
+       pkg_ver = 0;
+       pkg_ver_name = NULL;

I will try to send a fix for efi_fill_image_desc_array() as you mentioned, but if you agree that will be separated from this series.

Best regards,
Vincent.

Quoted 4 lines

Best regards

Heinrich

#9 lore raw

Re: [PATCH 2/2] efi_selftest: add minimal fmp test

Am 2. Oktober 2026 11:26:38 MESZ schrieb "Vincent Stehlé" <[email protected]>:

Quoted 49 lines · Heinrich Schuchardt
Quoted 2 lines · Vincent Stehlé
Quoted 1 line

Add a minimal test for the UEFI Firmware Management Protocol.

(..)

Quoted 22 lines

lib/efi_selftest/efi_selftest_fmp.c line 66

Quoted 8 lines
lib/efi_selftest/efi_selftest_fmp.c new file +8 -0
+	/* Determine buffer size */
+	img_info_size = 0;
+	ret = fmp->get_image_info(fmp, &img_info_size, NULL, NULL, NULL, NULL,
+				  NULL, NULL);
+	if (ret != EFI_BUFFER_TOO_SMALL) {
+		efi_st_error("GetImageInfo returned %u\n", (unsigned int)ret);
+		goto out;
+	}

This fails if the number of images is 0.

ERROR: GetImageInfo returned 2 (EFI_INVALID_PARAMETER)

(quoted diff) +8 -0
+struct efi_fw_image fw_images[] = {
+};
+
+struct efi_capsule_update_info update_info = {
+       .dfu_string = NULL,
+       .num_images = ARRAY_SIZE(fw_images),
+       .images = fw_images,
+};
Quoted 6 lines

This looks like a bug in efi_fill_image_desc_array((). Why does it return EFI_INVALID_PARAMETER if the number of images is 0?

We should just return *img_info_size = 0 and EFI_SUCCESS instead.

The test should return EFI_ST_SUCCESS in this case.

Hi Heinrich,

Thank you very much for reviewing.

I confirm that I could reproduce this corner case with your changes.

In the end I think the test (v2) itself is fine, as it does pass when I replace the calls to get_image_info() by the following code:

(quoted diff) +6 -0
+       img_info = NULL;
+       desc_ver = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION;
+       desc_cnt = 0;
+       desc_size = sizeof(struct efi_firmware_image_descriptor);
+       pkg_ver = 0;
+       pkg_ver_name = NULL;
Quoted 2 lines

I will try to send a fix for efi_fill_image_desc_array() as you mentioned, but if you agree that will be separated from this series.

The UEFI specification does not define if AllocatePool(size = 0) may return NULL which would lead to a failure of the subsequent Free().

I think we should return if size = 0 before trying to allocate memory.

Best regards

Heinrich

Quoted 8 lines

Best regards,
Vincent.

Quoted 4 lines

Best regards

Heinrich

#10 lore raw

v2 cover efi: fix and test FMP image info authentication attribute

In reply to Vincent Stehlé

Here is a couple of patches to:

- Do a small fix in the UEFI Firmware Management Protocol:
GetImageInfo() returns a correct authentication flag for the first image, but not for the subsequent ones.

- Add a minimal FMP selftest, just enough to catch this issue, and which should be easy enough to extend in the future.

---
Changes in v2:
- Rework FMP selftest with Simon's suggestions (changes details in the patch).
- Link to v1: https://patch.msgid.link/[email protected]

---
Vincent Stehlé (2):
efi_loader: fix image info authentication attribute
efi_selftest: add minimal fmp test

 lib/efi_loader/efi_firmware.c       |   2 +-
 lib/efi_selftest/Makefile           |   2 +
 lib/efi_selftest/efi_selftest_fmp.c | 240 ++++++++++++++++++++++++++++++++++++
 3 files changed, 243 insertions(+), 1 deletion(-)

---
base-commit: c92d8c3c431e37a17c3b37918037dbd7ade32d1e
change-id: 20260922-authi-329cc6a9a07c

Best regards,

Signature · 1 line
Vincent.
#11 lore raw

PATCH v2 1/2 efi_loader: fix image info authentication attribute

The GetImageInfo() function of the UEFI Firmware Management Protocol returns the authentication required attribute correctly in AttributesSetting only for the first image; fix this.

Fixes 88a2ef2720f5 ("efi_loader: Enable uefi capsule authentication")
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Tom Rini <[email protected]>
Cc Sughosh Ganu <[email protected]>
---
 lib/efi_loader/efi_firmware.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/efi_loader/efi_firmware.c +1 -1
index b41969c70fd..84de95f5c23 100644
@@ -364,7 +364,7 @@ static efi_status_t efi_fill_image_desc_array(
 
 		/* Check if the capsule authentication is enabled */
 		if (IS_ENABLED(CONFIG_EFI_CAPSULE_AUTHENTICATE))
-			image_info[0].attributes_setting |=
+			image_info[i].attributes_setting |=
 				IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED;
 
 		image_info[i].hardware_instance = 1;
Signature · 1 line
2.53.0
Reviewed-by on v2 1/2
#12 lore raw

Re: [PATCH v2 1/2] efi_loader: fix image info authentication attribute

Quoted 13 lines · Vincent Stehlé

efi_loader: fix image info authentication attribute

The GetImageInfo() function of the UEFI Firmware Management Protocol returns the authentication required attribute correctly in AttributesSetting only for the first image; fix this.

Fixes 88a2ef2720f5 ("efi_loader: Enable uefi capsule authentication")
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Tom Rini <[email protected]>
Cc Sughosh Ganu <[email protected]>
Quoted 2 lines

lib/efi_loader/efi_firmware.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by on v2 1/2
#13 lore raw

Re: [PATCH v2 1/2] efi_loader: fix image info authentication attribute

In reply to Vincent Stehlé
Quoted 5 lines · Vincent Stehlé

The GetImageInfo() function of the UEFI Firmware Management Protocol returns the authentication required attribute correctly in AttributesSetting only for the first image; fix this.

Quoted 7 lines
Fixes 88a2ef2720f5 ("efi_loader: Enable uefi capsule authentication")
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Tom Rini <[email protected]>
Cc Sughosh Ganu <[email protected]>

---

Quoted 20 lines
 lib/efi_loader/efi_firmware.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/efi_loader/efi_firmware.c +1 -2
index b41969c70fd..84de95f5c23 100644
@@ -364,7 +364,7 @@ static efi_status_t efi_fill_image_desc_array(
 
                /* Check if the capsule authentication is enabled */
                if (IS_ENABLED(CONFIG_EFI_CAPSULE_AUTHENTICATE))
-                       image_info[0].attributes_setting |=
+                       image_info[i].attributes_setting |=
                                IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED;
 
                image_info[i].hardware_instance = 1;
 
--

2.53.0

#14 lore raw

PATCH v2 2/2 efi_selftest: add minimal fmp test

In reply to Vincent Stehlé

Add a minimal test for the UEFI Firmware Management Protocol. At this point the test only does the following:

For all handles in the system with FMP,
- Get current firmware images info.
- For each image, verify consistency of the flags, with some attention to authentication.

This can be tested on the sandbox with the following command:

  ./u-boot -T -c "setenv efi_selftest firmware management protocol; \
                  bootefi selftest"

Testing with multiple handles supporting FMP can be done by enabling both CONFIG_EFI_CAPSULE_FIRMWARE_FIT and CONFIG_EFI_CAPSULE_FIRMWARE_RAW.

Cc Tom Rini <[email protected]>
Cc Heinrich Schuchardt <[email protected]>
Cc Ilias Apalodimas <[email protected]>
Cc Simon Glass <[email protected]>

---
Changes in v2:
- Check that DescriptorSize is not smaller than the sizeof() U-Boot knows about, and use DescriptorSize as the stride when iterating the img_info[] array.
- Use IS_ENABLED() instead of CONFIG_IS_ENABLED().
- Check that any bit set in AttributesSetting is also set in AttributesSupported.
- Check that AUTHENTICATION_REQUIRED is not set in AttributesSetting when authentication is disabled.
- Use locate_handle_buffer() to discover all handles in the system with FMP, and test them all.
(All those changes above suggested by Simon.)
- As a precaution, check that the total size of the descriptors is not larger than ImageInfoSize.
- Verify that U-Boot knows all the image attributes set in AttributesSetting and AttributesSupported.
- Move the original test to a test_fmp() function, which tests a single handle, and call it on all the discovered handles.
- Print also the handle when printing images informations.
- Rely only on AttributesSetting to determine if an image is updatable.
- Do not forget to free PackageVersionName.

---
 lib/efi_selftest/Makefile           |   2 +
 lib/efi_selftest/efi_selftest_fmp.c | 240 ++++++++++++++++++++++++++++++++++++
 2 files changed, 242 insertions(+)
lib/efi_selftest/Makefile +2 -0
index 67102648703..9882d9f2748 100644
@@ -80,6 +80,8 @@ obj-$(CONFIG_EFI_ESRT) += efi_selftest_esrt.o
 
 obj-$(CONFIG_EFI_DEBUG_SUPPORT) += efi_selftest_debug_support.o
 
+obj-$(CONFIG_EFI_CAPSULE_FIRMWARE) += efi_selftest_fmp.o
+
 targets += \
 efi_miniapp_file_image_exception.h \
 efi_miniapp_file_image_exit.h \
lib/efi_selftest/efi_selftest_fmp.c new file +240 -0

240 lines not on this page · raw message

Signature · 1 line
2.53.0
#15 lore raw

Re: [PATCH v2 2/2] efi_selftest: add minimal fmp test

Hi Vincent,

Quoted 28 lines · Vincent Stehlé

efi_selftest: add minimal fmp test

Add a minimal test for the UEFI Firmware Management Protocol. At this point the test only does the following:

For all handles in the system with FMP,
- Get current firmware images info.
- For each image, verify consistency of the flags, with some attention to authentication.

This can be tested on the sandbox with the following command:

  ./u-boot -T -c "setenv efi_selftest firmware management protocol; \
                  bootefi selftest"

Testing with multiple handles supporting FMP can be done by enabling both CONFIG_EFI_CAPSULE_FIRMWARE_FIT and CONFIG_EFI_CAPSULE_FIRMWARE_RAW.

lib/efi_selftest/Makefile | 2 +

 lib/efi_selftest/efi_selftest_fmp.c | 240 ++++++++++++++++++++++++++++++++++++
 2 files changed, 242 insertions(+)

lib/efi_selftest/efi_selftest_fmp.c line 3

Quoted 3 lines
lib/efi_selftest/efi_selftest_fmp.c +3 -0
@@ -0,0 +1,240 @@
+     if (desc_size < sizeof(struct efi_firmware_image_descriptor) ||
+         __builtin_mul_overflow(desc_size, desc_cnt, &total_size) ||
+         total_size > img_info_size) {

Please can you use check_mul_overflow() from <linux/overflow.h> rather than the builtin? Nothing else in lib/efi_selftest or lib/efi_loader uses the builtin directly.

lib/efi_selftest/efi_selftest_fmp.c line 3

Quoted 5 lines
lib/efi_selftest/efi_selftest_fmp.c +3 -0
@@ -0,0 +1,240 @@
+             if (!IS_ENABLED(CONFIG_EFI_CAPSULE_AUTHENTICATE) &&
+                 (attr_set & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE) &&
+                 (attr_set & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED)) {

Just to check, is there a reason to limit this to updatable images? I suspect AUTHENTICATION_REQUIRED should never be set when authentication is disabled, so the IMAGE_UPDATABLE condition could be dropped. Not a blocker though.

lib/efi_selftest/efi_selftest_fmp.c line 3

Quoted 5 lines
lib/efi_selftest/efi_selftest_fmp.c +3 -0
@@ -0,0 +1,240 @@
+     int i, result = EFI_ST_SUCCESS;
+     efi_handle_t *buffer = NULL;
+     efi_uintn_t count;

Since count is an efi_uintn_t, please can you make i the same type, to avoid the signed/unsigned comparison in the loop?

Regards,
Simon

#16 lore raw

Re: [PATCH v2 2/2] efi_selftest: add minimal fmp test

Quoted 29 lines · Simon Glass

Hi Vincent,

Quoted 25 lines · Vincent Stehlé

efi_selftest: add minimal fmp test

Add a minimal test for the UEFI Firmware Management Protocol. At this point the test only does the following:

For all handles in the system with FMP,
- Get current firmware images info.
- For each image, verify consistency of the flags, with some attention to authentication.

This can be tested on the sandbox with the following command:

  ./u-boot -T -c "setenv efi_selftest firmware management protocol; \
                  bootefi selftest"

Testing with multiple handles supporting FMP can be done by enabling both CONFIG_EFI_CAPSULE_FIRMWARE_FIT and CONFIG_EFI_CAPSULE_FIRMWARE_RAW.

lib/efi_selftest/Makefile | 2 +

 lib/efi_selftest/efi_selftest_fmp.c | 240 ++++++++++++++++++++++++++++++++++++
 2 files changed, 242 insertions(+)
Quoted 9 lines

lib/efi_selftest/efi_selftest_fmp.c line 3

Quoted 5 lines
lib/efi_selftest/efi_selftest_fmp.c +3 -0
@@ -0,0 +1,240 @@
+     if (desc_size < sizeof(struct efi_firmware_image_descriptor) ||
+         __builtin_mul_overflow(desc_size, desc_cnt, &total_size) ||
+         total_size > img_info_size) {

Please can you use check_mul_overflow() from <linux/overflow.h> rather than the builtin? Nothing else in lib/efi_selftest or lib/efi_loader uses the builtin directly.

Importing that header first and making use of it more widely second would be a reasonable thing for a backlog / TODO list for someone. As Rasmus is the original author in Linux, it might even be on his list somewhere (along with re-syncing the related compiler header parts).

Signature · 1 line
Tom