All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] efi_loader: fix image and load_options leak on FDT load failure
@ 2026-10-22 21:44 Yuho Choi
  2026-10-23  7:04 ` Carlo Caione
  2026-10-23  7:34 ` Ilias Apalodimas
  0 siblings, 2 replies; 3+ messages in thread
From: Yuho Choi @ 2026-10-22 21:44 UTC (permalink / raw)
  To: Heinrich Schuchardt, Ilias Apalodimas
  Cc: Tom Rini, Carlo Caione, u-boot, Yuho Choi

When efi_bootmgr_run() attempts to load an FDT specified in the active
Boot#### option on non-ACPI platforms, load_fdt_from_load_option() may
fail (e.g. if the file is missing or unreadable).

In this failure path, efi_bootmgr_run() returns the error code immediately,
skipping the cleanup code at the end of the function. This leaks the loaded
image handle, allocated memory pages, loaded image protocol, and the
malloc'd load_options buffer.

Fix this by jumping to the cleanup label 'out' so that efi_unload_image()
and free(load_options) are called before returning.

Fixes: 39bac24a48b0 ("efi_loader: load device-tree specified in boot option")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
 lib/efi_loader/efi_bootmgr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index 51ecb6ec1f..934f0c4060 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -1323,7 +1323,7 @@ efi_status_t efi_bootmgr_run(void *fdt)
 		if (!fdt) {
 			ret = load_fdt_from_load_option(&fdt_lo);
 			if (ret != EFI_SUCCESS)
-				return ret;
+				goto out;
 			if (fdt_lo)
 				fdt = fdt_lo;
 		}
@@ -1339,6 +1339,7 @@ efi_status_t efi_bootmgr_run(void *fdt)
 	 */
 	ret = efi_install_fdt(fdt);
 
+out:
 	if (!IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) {
 		free(fdt_lo);
 		if (fdt_distro)
-- 
2.43.0


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

* Re: [PATCH] efi_loader: fix image and load_options leak on FDT load failure
  2026-10-22 21:44 [PATCH] efi_loader: fix image and load_options leak on FDT load failure Yuho Choi
@ 2026-10-23  7:04 ` Carlo Caione
  2026-10-23  7:34 ` Ilias Apalodimas
  1 sibling, 0 replies; 3+ messages in thread
From: Carlo Caione @ 2026-10-23  7:04 UTC (permalink / raw)
  To: Yuho Choi; +Cc: Heinrich Schuchardt, Ilias Apalodimas, Tom Rini, u-boot

On Thu, Oct 22, 2026 at 17:44:28 +0100, Yuho Choi wrote:
> When efi_bootmgr_run() attempts to load an FDT specified in the active
> Boot#### option on non-ACPI platforms, load_fdt_from_load_option() may
> fail (e.g. if the file is missing or unreadable).
> 
> In this failure path, efi_bootmgr_run() returns the error code immediately,
> skipping the cleanup code at the end of the function. This leaks the loaded
> image handle, allocated memory pages, loaded image protocol, and the
> malloc'd load_options buffer.
> 
> Fix this by jumping to the cleanup label 'out' so that efi_unload_image()
> and free(load_options) are called before returning.
> 
> Fixes: 39bac24a48b0 ("efi_loader: load device-tree specified in boot option")
> Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>

I think this should be 39bac24a48bb. Besides that:

Reviewed-by: Carlo Caione <ccaione@baylibre.com>

> ---
>  lib/efi_loader/efi_bootmgr.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
> index 51ecb6ec1f..934f0c4060 100644
> --- a/lib/efi_loader/efi_bootmgr.c
> +++ b/lib/efi_loader/efi_bootmgr.c
> @@ -1323,7 +1323,7 @@ efi_status_t efi_bootmgr_run(void *fdt)
>  		if (!fdt) {
>  			ret = load_fdt_from_load_option(&fdt_lo);
>  			if (ret != EFI_SUCCESS)
> -				return ret;
> +				goto out;
>  			if (fdt_lo)
>  				fdt = fdt_lo;
>  		}
> @@ -1339,6 +1339,7 @@ efi_status_t efi_bootmgr_run(void *fdt)
>  	 */
>  	ret = efi_install_fdt(fdt);
>  
> +out:
>  	if (!IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) {
>  		free(fdt_lo);
>  		if (fdt_distro)
> -- 
> 2.43.0
> 

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

* Re: [PATCH] efi_loader: fix image and load_options leak on FDT load failure
  2026-10-22 21:44 [PATCH] efi_loader: fix image and load_options leak on FDT load failure Yuho Choi
  2026-10-23  7:04 ` Carlo Caione
@ 2026-10-23  7:34 ` Ilias Apalodimas
  1 sibling, 0 replies; 3+ messages in thread
From: Ilias Apalodimas @ 2026-10-23  7:34 UTC (permalink / raw)
  To: Yuho Choi; +Cc: Heinrich Schuchardt, Tom Rini, Carlo Caione, u-boot

On Fri, 23 Oct 2026 at 00:44, Yuho Choi <oss.patchbox@gmail.com> wrote:
>
> When efi_bootmgr_run() attempts to load an FDT specified in the active
> Boot#### option on non-ACPI platforms, load_fdt_from_load_option() may
> fail (e.g. if the file is missing or unreadable).
>
> In this failure path, efi_bootmgr_run() returns the error code immediately,
> skipping the cleanup code at the end of the function. This leaks the loaded
> image handle, allocated memory pages, loaded image protocol, and the
> malloc'd load_options buffer.
>
> Fix this by jumping to the cleanup label 'out' so that efi_unload_image()
> and free(load_options) are called before returning.
>
> Fixes: 39bac24a48b0 ("efi_loader: load device-tree specified in boot option")

As Carlo pointed out, the SHA1 is probably from an internal tree;
39bac24a48bb is the right one

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

> Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
> ---
>  lib/efi_loader/efi_bootmgr.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
> index 51ecb6ec1f..934f0c4060 100644
> --- a/lib/efi_loader/efi_bootmgr.c
> +++ b/lib/efi_loader/efi_bootmgr.c
> @@ -1323,7 +1323,7 @@ efi_status_t efi_bootmgr_run(void *fdt)
>                 if (!fdt) {
>                         ret = load_fdt_from_load_option(&fdt_lo);
>                         if (ret != EFI_SUCCESS)
> -                               return ret;
> +                               goto out;
>                         if (fdt_lo)
>                                 fdt = fdt_lo;
>                 }
> @@ -1339,6 +1339,7 @@ efi_status_t efi_bootmgr_run(void *fdt)
>          */
>         ret = efi_install_fdt(fdt);
>
> +out:
>         if (!IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) {
>                 free(fdt_lo);
>                 if (fdt_distro)
> --
> 2.43.0
>

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

end of thread, other threads:[~2026-10-23  7:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-22 21:44 [PATCH] efi_loader: fix image and load_options leak on FDT load failure Yuho Choi
2026-10-23  7:04 ` Carlo Caione
2026-10-23  7:34 ` Ilias Apalodimas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.