diff mbox series

efi_loader: Don't delete variable from memory if adding a new one failed

Message ID 20240403154353.440959-1-ilias.apalodimas@linaro.org
State New
Headers show
Series efi_loader: Don't delete variable from memory if adding a new one failed | expand

Commit Message

Ilias Apalodimas April 3, 2024, 3:43 p.m. UTC
From: Ilias Apalodimas <apalos@gmail.com>

Our efi_var_mem_xxx() functions don't have a replace variant. Instead we
add a new variable and delete the old instance when trying to replace a
variable. Currently we delete the old version without checking the new
one got added

Signed-off-by: Ilias Apalodimas <apalos@gmail.com>
---
 lib/efi_loader/efi_variable.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

--
2.43.0

Comments

Heinrich Schuchardt April 3, 2024, 8:33 p.m. UTC | #1
On 4/3/24 17:43, Ilias Apalodimas wrote:
> From: Ilias Apalodimas <apalos@gmail.com>
> 
> Our efi_var_mem_xxx() functions don't have a replace variant. Instead we
> add a new variable and delete the old instance when trying to replace a
> variable. Currently we delete the old version without checking the new
> one got added
> 
> Signed-off-by: Ilias Apalodimas <apalos@gmail.com>
> ---
>   lib/efi_loader/efi_variable.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
> index 40f7a0fb10d5..b6e60626a260 100644
> --- a/lib/efi_loader/efi_variable.c
> +++ b/lib/efi_loader/efi_variable.c
> @@ -342,11 +342,12 @@ efi_status_t efi_set_variable_int(const u16 *variable_name,
>   		ret = efi_var_mem_ins(variable_name, vendor, attributes,
>   				      data_size, data, 0, NULL, time);
>   	}
> -	efi_var_mem_del(var);
> 
>   	if (ret != EFI_SUCCESS)
>   		return ret;
> 
> +	efi_var_mem_del(var);
> +
>   	if (var_type == EFI_AUTH_VAR_PK)
>   		ret = efi_init_secure_state();
>   	else
> --
> 2.43.0
> 

Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
diff mbox series

Patch

diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index 40f7a0fb10d5..b6e60626a260 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -342,11 +342,12 @@  efi_status_t efi_set_variable_int(const u16 *variable_name,
 		ret = efi_var_mem_ins(variable_name, vendor, attributes,
 				      data_size, data, 0, NULL, time);
 	}
-	efi_var_mem_del(var);

 	if (ret != EFI_SUCCESS)
 		return ret;

+	efi_var_mem_del(var);
+
 	if (var_type == EFI_AUTH_VAR_PK)
 		ret = efi_init_secure_state();
 	else