diff mbox series

[1/3] efi_loader: correct handling of EFI binary return code

Message ID 20240316093644.54869-2-heinrich.schuchardt@canonical.com
State Accepted, archived
Commit 6f90a05a04d8377ae85f9aba8fc03955da72eba0
Delegated to: Heinrich Schuchardt
Headers show
Series cmd: bootefi: fix error handling | expand

Commit Message

Heinrich Schuchardt March 16, 2024, 9:36 a.m. UTC
Running an EFI binary loaded via tftp using the bootefi command results in
showing the usage help.

We should not try to remove protocol interfaces from a NULL handle.

Fixes: 6422820ac3e5 ("efi_loader: split unrelated code from efi_bootmgr.c")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 lib/efi_loader/efi_bootbin.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

Comments

Ilias Apalodimas March 20, 2024, 9:18 p.m. UTC | #1
Hi Heinrich

On Sat, 16 Mar 2024 at 11:37, Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> Running an EFI binary loaded via tftp using the bootefi command results in
> showing the usage help.

The commit message sounds a bit off. The real problem is removing
protocols from a non existent handle right?
The help message was fixed in a subsequent patch

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

>
> We should not try to remove protocol interfaces from a NULL handle.
>
> Fixes: 6422820ac3e5 ("efi_loader: split unrelated code from efi_bootmgr.c")
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  lib/efi_loader/efi_bootbin.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/lib/efi_loader/efi_bootbin.c b/lib/efi_loader/efi_bootbin.c
> index 733cc1a61b5..b7910f78fb6 100644
> --- a/lib/efi_loader/efi_bootbin.c
> +++ b/lib/efi_loader/efi_bootbin.c
> @@ -125,7 +125,7 @@ efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size)
>         efi_handle_t mem_handle = NULL, handle;
>         struct efi_device_path *file_path = NULL;
>         struct efi_device_path *msg_path;
> -       efi_status_t ret, ret2;
> +       efi_status_t ret;
>         u16 *load_options;
>
>         if (!bootefi_device_path || !bootefi_image_path) {
> @@ -172,11 +172,17 @@ efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size)
>         ret = do_bootefi_exec(handle, load_options);
>
>  out:
> -       ret2 = efi_uninstall_multiple_protocol_interfaces(mem_handle,
> -                                                         &efi_guid_device_path,
> -                                                         file_path, NULL);
> +       if (mem_handle) {
> +               efi_status_t r;
> +
> +               r = efi_uninstall_multiple_protocol_interfaces(
> +                       mem_handle, &efi_guid_device_path, file_path, NULL);
> +               if (r != EFI_SUCCESS)
> +                       log_err("Uninstalling protocol interfaces failed\n");
> +       }
>         efi_free_pool(file_path);
> -       return (ret != EFI_SUCCESS) ? ret : ret2;
> +
> +       return ret;
>  }
>
>  /**
> --
> 2.43.0
>
diff mbox series

Patch

diff --git a/lib/efi_loader/efi_bootbin.c b/lib/efi_loader/efi_bootbin.c
index 733cc1a61b5..b7910f78fb6 100644
--- a/lib/efi_loader/efi_bootbin.c
+++ b/lib/efi_loader/efi_bootbin.c
@@ -125,7 +125,7 @@  efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size)
 	efi_handle_t mem_handle = NULL, handle;
 	struct efi_device_path *file_path = NULL;
 	struct efi_device_path *msg_path;
-	efi_status_t ret, ret2;
+	efi_status_t ret;
 	u16 *load_options;
 
 	if (!bootefi_device_path || !bootefi_image_path) {
@@ -172,11 +172,17 @@  efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size)
 	ret = do_bootefi_exec(handle, load_options);
 
 out:
-	ret2 = efi_uninstall_multiple_protocol_interfaces(mem_handle,
-							  &efi_guid_device_path,
-							  file_path, NULL);
+	if (mem_handle) {
+		efi_status_t r;
+
+		r = efi_uninstall_multiple_protocol_interfaces(
+			mem_handle, &efi_guid_device_path, file_path, NULL);
+		if (r != EFI_SUCCESS)
+			log_err("Uninstalling protocol interfaces failed\n");
+	}
 	efi_free_pool(file_path);
-	return (ret != EFI_SUCCESS) ? ret : ret2;
+
+	return ret;
 }
 
 /**