diff mbox series

[v2] efi: libstub: only free priv.runtime_map when allocated

Message ID 20240423135928.1200-1-hagarhem@amazon.com
State Superseded
Headers show
Series [v2] efi: libstub: only free priv.runtime_map when allocated | expand

Commit Message

Hagar Hemdan April 23, 2024, 1:59 p.m. UTC
priv.runtime_map is only allocated when efi_novamap is not set.
Otherwise, it is an uninitialized value.
In the error path, it is freed unconditionally.
Avoid passing an uninitialized value to free_pool.
Free priv.runtime_map only when it was allocated.

This bug was discovered and resolved using Coverity Static Analysis
Security Testing (SAST) by Synopsys, Inc.

Fixes: f80d26043af9 ("efi: libstub: avoid efi_get_memory_map() for allocating the virt map")
Cc: stable@vger.kernel.org
Signed-off-by: Hagar Hemdan <hagarhem@amazon.com>
---
v2: added Cc stable tag to the commit message as requested by kernel
test robot.
---
 drivers/firmware/efi/libstub/fdt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Ard Biesheuvel April 29, 2024, 3:48 p.m. UTC | #1
On Tue, 23 Apr 2024 at 16:00, Hagar Hemdan <hagarhem@amazon.com> wrote:
>
> priv.runtime_map is only allocated when efi_novamap is not set.
> Otherwise, it is an uninitialized value.
> In the error path, it is freed unconditionally.
> Avoid passing an uninitialized value to free_pool.
> Free priv.runtime_map only when it was allocated.
>
> This bug was discovered and resolved using Coverity Static Analysis
> Security Testing (SAST) by Synopsys, Inc.
>
> Fixes: f80d26043af9 ("efi: libstub: avoid efi_get_memory_map() for allocating the virt map")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hagar Hemdan <hagarhem@amazon.com>
> ---
> v2: added Cc stable tag to the commit message as requested by kernel
> test robot.
> ---
>  drivers/firmware/efi/libstub/fdt.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>

Queued up in efi/next, thanks.

> diff --git a/drivers/firmware/efi/libstub/fdt.c b/drivers/firmware/efi/libstub/fdt.c
> index 70e9789ff9de..6a337f1f8787 100644
> --- a/drivers/firmware/efi/libstub/fdt.c
> +++ b/drivers/firmware/efi/libstub/fdt.c
> @@ -335,8 +335,8 @@ efi_status_t allocate_new_fdt_and_exit_boot(void *handle,
>
>  fail:
>         efi_free(fdt_size, fdt_addr);
> -
> -       efi_bs_call(free_pool, priv.runtime_map);
> +       if (!efi_novamap)
> +               efi_bs_call(free_pool, priv.runtime_map);
>
>         return EFI_LOAD_ERROR;
>  }
> --
> 2.40.1
>
diff mbox series

Patch

diff --git a/drivers/firmware/efi/libstub/fdt.c b/drivers/firmware/efi/libstub/fdt.c
index 70e9789ff9de..6a337f1f8787 100644
--- a/drivers/firmware/efi/libstub/fdt.c
+++ b/drivers/firmware/efi/libstub/fdt.c
@@ -335,8 +335,8 @@  efi_status_t allocate_new_fdt_and_exit_boot(void *handle,
 
 fail:
 	efi_free(fdt_size, fdt_addr);
-
-	efi_bs_call(free_pool, priv.runtime_map);
+	if (!efi_novamap)
+		efi_bs_call(free_pool, priv.runtime_map);
 
 	return EFI_LOAD_ERROR;
 }