public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH 1/1] efi_loader: CloseProtocol in tcg2_measure_gpt_data
@ 2022-10-07 13:38 Heinrich Schuchardt
  2022-10-07 17:05 ` Ilias Apalodimas
  2022-10-10  7:55 ` Ilias Apalodimas
  0 siblings, 2 replies; 3+ messages in thread
From: Heinrich Schuchardt @ 2022-10-07 13:38 UTC (permalink / raw)
  To: Ilias Apalodimas; +Cc: Masahisa Kojima, u-boot, Heinrich Schuchardt

The CloseProtocol() boot service requires a handle as first argument.
Passing the protocol interface is incorrect.

CloseProtocol() only has an effect if called with a non-zero value for
agent_handle. HandleProtocol() uses an opaque agent_handle when invoking
OpenProtocol() (currently NULL). Therefore HandleProtocol() should be
avoided.

* Replace the LocateHandle() call by efi_search_protocol().
* Remove the CloseProtocol() call.
* Remove a superfluous goto.

Fixes: ce3dbc5d080d ("efi_loader: add UEFI GPT measurement")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 lib/efi_loader/efi_tcg2.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c
index 99ec3a5486..a525ebf75b 100644
--- a/lib/efi_loader/efi_tcg2.c
+++ b/lib/efi_loader/efi_tcg2.c
@@ -2053,7 +2053,7 @@ tcg2_measure_gpt_data(struct udevice *dev,
 {
 	efi_status_t ret;
 	efi_handle_t handle;
-	struct efi_handler *dp_handler;
+	struct efi_handler *dp_handler, *io_handler;
 	struct efi_device_path *orig_device_path;
 	struct efi_device_path *device_path;
 	struct efi_device_path *dp;
@@ -2098,10 +2098,10 @@ tcg2_measure_gpt_data(struct udevice *dev,
 	if (ret != EFI_SUCCESS)
 		goto out1;
 
-	ret = EFI_CALL(efi_handle_protocol(handle,
-					   &efi_block_io_guid, (void **)&block_io));
+	ret = efi_search_protocol(handle, &efi_block_io_guid, &io_handler);
 	if (ret != EFI_SUCCESS)
 		goto out1;
+	block_io = io_handler->protocol_interface;
 
 	gpt_h = memalign(block_io->media->io_align, block_io->media->block_size);
 	if (!gpt_h) {
@@ -2164,12 +2164,8 @@ tcg2_measure_gpt_data(struct udevice *dev,
 	}
 
 	ret = tcg2_measure_event(dev, 5, EV_EFI_GPT_EVENT, event_size, (u8 *)event);
-	if (ret != EFI_SUCCESS)
-		goto out2;
 
 out2:
-	EFI_CALL(efi_close_protocol((efi_handle_t)block_io, &efi_block_io_guid,
-				    NULL, NULL));
 	free(gpt_h);
 	free(entry);
 	free(event);
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] efi_loader: CloseProtocol in tcg2_measure_gpt_data
  2022-10-07 13:38 [PATCH 1/1] efi_loader: CloseProtocol in tcg2_measure_gpt_data Heinrich Schuchardt
@ 2022-10-07 17:05 ` Ilias Apalodimas
  2022-10-10  7:55 ` Ilias Apalodimas
  1 sibling, 0 replies; 3+ messages in thread
From: Ilias Apalodimas @ 2022-10-07 17:05 UTC (permalink / raw)
  To: Heinrich Schuchardt; +Cc: Masahisa Kojima, u-boot

On Fri, Oct 07, 2022 at 03:38:45PM +0200, Heinrich Schuchardt wrote:
> The CloseProtocol() boot service requires a handle as first argument.
> Passing the protocol interface is incorrect.
> 
> CloseProtocol() only has an effect if called with a non-zero value for
> agent_handle. HandleProtocol() uses an opaque agent_handle when invoking
> OpenProtocol() (currently NULL). Therefore HandleProtocol() should be
> avoided.
> 
> * Replace the LocateHandle() call by efi_search_protocol().
> * Remove the CloseProtocol() call.
> * Remove a superfluous goto.
> 
> Fixes: ce3dbc5d080d ("efi_loader: add UEFI GPT measurement")
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  lib/efi_loader/efi_tcg2.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c
> index 99ec3a5486..a525ebf75b 100644
> --- a/lib/efi_loader/efi_tcg2.c
> +++ b/lib/efi_loader/efi_tcg2.c
> @@ -2053,7 +2053,7 @@ tcg2_measure_gpt_data(struct udevice *dev,
>  {
>  	efi_status_t ret;
>  	efi_handle_t handle;
> -	struct efi_handler *dp_handler;
> +	struct efi_handler *dp_handler, *io_handler;
>  	struct efi_device_path *orig_device_path;
>  	struct efi_device_path *device_path;
>  	struct efi_device_path *dp;
> @@ -2098,10 +2098,10 @@ tcg2_measure_gpt_data(struct udevice *dev,
>  	if (ret != EFI_SUCCESS)
>  		goto out1;
>  
> -	ret = EFI_CALL(efi_handle_protocol(handle,
> -					   &efi_block_io_guid, (void **)&block_io));
> +	ret = efi_search_protocol(handle, &efi_block_io_guid, &io_handler);
>  	if (ret != EFI_SUCCESS)
>  		goto out1;
> +	block_io = io_handler->protocol_interface;
>  
>  	gpt_h = memalign(block_io->media->io_align, block_io->media->block_size);
>  	if (!gpt_h) {
> @@ -2164,12 +2164,8 @@ tcg2_measure_gpt_data(struct udevice *dev,
>  	}
>  
>  	ret = tcg2_measure_event(dev, 5, EV_EFI_GPT_EVENT, event_size, (u8 *)event);
> -	if (ret != EFI_SUCCESS)
> -		goto out2;
>  
>  out2:
> -	EFI_CALL(efi_close_protocol((efi_handle_t)block_io, &efi_block_io_guid,
> -				    NULL, NULL));
>  	free(gpt_h);
>  	free(entry);
>  	free(event);
> -- 
> 2.37.2
> 

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] efi_loader: CloseProtocol in tcg2_measure_gpt_data
  2022-10-07 13:38 [PATCH 1/1] efi_loader: CloseProtocol in tcg2_measure_gpt_data Heinrich Schuchardt
  2022-10-07 17:05 ` Ilias Apalodimas
@ 2022-10-10  7:55 ` Ilias Apalodimas
  1 sibling, 0 replies; 3+ messages in thread
From: Ilias Apalodimas @ 2022-10-10  7:55 UTC (permalink / raw)
  To: Heinrich Schuchardt; +Cc: Masahisa Kojima, u-boot

On Fri, Oct 07, 2022 at 03:38:45PM +0200, Heinrich Schuchardt wrote:
> The CloseProtocol() boot service requires a handle as first argument.
> Passing the protocol interface is incorrect.
> 
> CloseProtocol() only has an effect if called with a non-zero value for
> agent_handle. HandleProtocol() uses an opaque agent_handle when invoking
> OpenProtocol() (currently NULL). Therefore HandleProtocol() should be
> avoided.
> 
> * Replace the LocateHandle() call by efi_search_protocol().
> * Remove the CloseProtocol() call.
> * Remove a superfluous goto.
> 
> Fixes: ce3dbc5d080d ("efi_loader: add UEFI GPT measurement")
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  lib/efi_loader/efi_tcg2.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c
> index 99ec3a5486..a525ebf75b 100644
> --- a/lib/efi_loader/efi_tcg2.c
> +++ b/lib/efi_loader/efi_tcg2.c
> @@ -2053,7 +2053,7 @@ tcg2_measure_gpt_data(struct udevice *dev,
>  {
>  	efi_status_t ret;
>  	efi_handle_t handle;
> -	struct efi_handler *dp_handler;
> +	struct efi_handler *dp_handler, *io_handler;
>  	struct efi_device_path *orig_device_path;
>  	struct efi_device_path *device_path;
>  	struct efi_device_path *dp;
> @@ -2098,10 +2098,10 @@ tcg2_measure_gpt_data(struct udevice *dev,
>  	if (ret != EFI_SUCCESS)
>  		goto out1;
>  
> -	ret = EFI_CALL(efi_handle_protocol(handle,
> -					   &efi_block_io_guid, (void **)&block_io));
> +	ret = efi_search_protocol(handle, &efi_block_io_guid, &io_handler);
>  	if (ret != EFI_SUCCESS)
>  		goto out1;
> +	block_io = io_handler->protocol_interface;
>  
>  	gpt_h = memalign(block_io->media->io_align, block_io->media->block_size);
>  	if (!gpt_h) {
> @@ -2164,12 +2164,8 @@ tcg2_measure_gpt_data(struct udevice *dev,
>  	}
>  
>  	ret = tcg2_measure_event(dev, 5, EV_EFI_GPT_EVENT, event_size, (u8 *)event);
> -	if (ret != EFI_SUCCESS)
> -		goto out2;
>  
>  out2:
> -	EFI_CALL(efi_close_protocol((efi_handle_t)block_io, &efi_block_io_guid,
> -				    NULL, NULL));
>  	free(gpt_h);
>  	free(entry);
>  	free(event);
> -- 
> 2.37.2
> 

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-10-10  7:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-07 13:38 [PATCH 1/1] efi_loader: CloseProtocol in tcg2_measure_gpt_data Heinrich Schuchardt
2022-10-07 17:05 ` Ilias Apalodimas
2022-10-10  7:55 ` Ilias Apalodimas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox