diff mbox series

[v2,1/4] EFI: Populate descriptor_count value only when image_info_size is not zero

Message ID 20220601180041.340240-2-sughosh.ganu@linaro.org
State Accepted, archived
Commit 6a463bc1c9bde3326825369061803d281cf423d8
Delegated to: Heinrich Schuchardt
Headers show
Series EFI: Miscellaneous capsule update fixes | expand

Commit Message

Sughosh Ganu June 1, 2022, 6 p.m. UTC
The GetImageInfo function of the Firmware Mangement Protocol(FMP) gets
called initially to query the size of the image descriptor array that
would have to be allocated. During this call, the rest of the function
arguments, specifically pointers might be passed as NULL. Do not
populate the descriptor_count value before it is known that the call
to GetImageInfo has been made with the allocated buffer for the image
descriptors.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---

Changes since V1: None

 lib/efi_loader/efi_firmware.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Peter Griffin June 10, 2022, 7:07 p.m. UTC | #1
Hi Sughosh,

On Wed, 1 Jun 2022 at 19:01, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:

> The GetImageInfo function of the Firmware Mangement Protocol(FMP) gets
> called initially to query the size of the image descriptor array that
> would have to be allocated. During this call, the rest of the function
> arguments, specifically pointers might be passed as NULL. Do not
> populate the descriptor_count value before it is known that the call
> to GetImageInfo has been made with the allocated buffer for the image
> descriptors.
>
> Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---
>

This patch solves the hang issue I observed on master with
CapsuleApp.efi when doing

FS5:EFI/BOOT/app/CapsuleApp.efi -P

Which is part of the SystemReady IR ACS compliance suite.
Tested on a RockPi4b board.

Tested-by: Peter Griffin <peter.griffin@linaro.org>

Peter


> Changes since V1: None
>
>  lib/efi_loader/efi_firmware.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
> index fe4e084106..9cdefab41f 100644
> --- a/lib/efi_loader/efi_firmware.c
> +++ b/lib/efi_loader/efi_firmware.c
> @@ -130,9 +130,6 @@ static efi_status_t efi_fill_image_desc_array(
>         struct efi_fw_image *fw_array;
>         int i;
>
> -       fw_array = update_info.images;
> -       *descriptor_count = num_image_type_guids;
> -
>         total_size = sizeof(*image_info) * num_image_type_guids;
>
>         if (*image_info_size < total_size) {
> @@ -142,6 +139,8 @@ static efi_status_t efi_fill_image_desc_array(
>         }
>         *image_info_size = total_size;
>
> +       fw_array = update_info.images;
> +       *descriptor_count = num_image_type_guids;
>         *descriptor_version = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION;
>         *descriptor_size = sizeof(*image_info);
>         *package_version = 0xffffffff; /* not supported */
> --
> 2.25.1
>
>
diff mbox series

Patch

diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
index fe4e084106..9cdefab41f 100644
--- a/lib/efi_loader/efi_firmware.c
+++ b/lib/efi_loader/efi_firmware.c
@@ -130,9 +130,6 @@  static efi_status_t efi_fill_image_desc_array(
 	struct efi_fw_image *fw_array;
 	int i;
 
-	fw_array = update_info.images;
-	*descriptor_count = num_image_type_guids;
-
 	total_size = sizeof(*image_info) * num_image_type_guids;
 
 	if (*image_info_size < total_size) {
@@ -142,6 +139,8 @@  static efi_status_t efi_fill_image_desc_array(
 	}
 	*image_info_size = total_size;
 
+	fw_array = update_info.images;
+	*descriptor_count = num_image_type_guids;
 	*descriptor_version = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION;
 	*descriptor_size = sizeof(*image_info);
 	*package_version = 0xffffffff; /* not supported */