From c33d389c7ab5924fc7892edaf11798d644a2d824 Mon Sep 17 00:00:00 2001 From: Vincent Stehlé Date: Tue, 13 Dec 2022 22:39:09 +0100 Subject: efi_loader: fix get_package_list_handle() status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the HII protocol function get_package_list_handle() is called with an invalid package list handle, it returns EFI_NOT_FOUND but this is not in its list of possible status codes as per the EFI specification. Return EFI_INVALID_PARAMETER instead to fix conformance. Signed-off-by: Vincent Stehlé Cc: Heinrich Schuchardt Cc: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- lib/efi_loader/efi_hii.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_hii.c b/lib/efi_loader/efi_hii.c index 75ff58aafa5..27db3be6a17 100644 --- a/lib/efi_loader/efi_hii.c +++ b/lib/efi_loader/efi_hii.c @@ -780,7 +780,7 @@ get_package_list_handle(const struct efi_hii_database_protocol *this, } } - return EFI_EXIT(EFI_NOT_FOUND); + return EFI_EXIT(EFI_INVALID_PARAMETER); } const struct efi_hii_database_protocol efi_hii_database = { -- cgit v1.3.1 From fcf583b4a7f74de1475a953bd934efcdd4e34309 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 29 Dec 2022 09:23:03 +0100 Subject: efi_loader: typo non-volatile in efi_var_restore It is volatile variables that we do not allow to be restored from file. Signed-off-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- lib/efi_loader/efi_var_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_var_file.c b/lib/efi_loader/efi_var_file.c index 3d58caa13da..de9ba8de996 100644 --- a/lib/efi_loader/efi_var_file.c +++ b/lib/efi_loader/efi_var_file.c @@ -176,7 +176,7 @@ efi_status_t efi_var_restore(struct efi_var_file *buf, bool safe) data = var->name + u16_strlen(var->name) + 1; /* - * Secure boot related and non-volatile variables shall only be + * Secure boot related and volatile variables shall only be * restored from U-Boot's preseed. */ if (!safe && -- cgit v1.3.1 From 77bb14758dcb1876c7bbfa4cead67c90f2d86a44 Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Thu, 29 Dec 2022 10:13:22 +0200 Subject: efi_loader: avoid adding variables twice When the efi subsystem starts we restore variables that are both in a file or stored into the .efi_runtime section of U-Boot. However once a variable gets created or changed the preseeded entries will end up in the file. As a consequence on the next boot we will end up adding identical variable entries twice. Fix this by checking if the to be inserted variable already exists. Also swap the restoration order and start with the file instead of the builtin variables, so a user can replace the preseeded ones if needed. Tested-by: Leo Yan Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- lib/efi_loader/efi_var_file.c | 2 ++ lib/efi_loader/efi_variable.c | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_var_file.c b/lib/efi_loader/efi_var_file.c index de9ba8de996..62e071bd834 100644 --- a/lib/efi_loader/efi_var_file.c +++ b/lib/efi_loader/efi_var_file.c @@ -187,6 +187,8 @@ efi_status_t efi_var_restore(struct efi_var_file *buf, bool safe) continue; if (!var->length) continue; + if (efi_var_mem_find(&var->guid, var->name, NULL)) + continue; ret = efi_var_mem_ins(var->name, &var->guid, var->attr, var->length, data, 0, NULL, var->time); diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index 8ca2d85694c..503a33ed65c 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -425,6 +425,9 @@ efi_status_t efi_init_variables(void) if (ret != EFI_SUCCESS) return ret; + ret = efi_var_from_file(); + if (ret != EFI_SUCCESS) + return ret; if (IS_ENABLED(CONFIG_EFI_VARIABLES_PRESEED)) { ret = efi_var_restore((struct efi_var_file *) __efi_var_file_begin, true); @@ -432,9 +435,6 @@ efi_status_t efi_init_variables(void) log_err("Invalid EFI variable seed\n"); } - ret = efi_var_from_file(); - if (ret != EFI_SUCCESS) - return ret; return efi_init_secure_state(); } -- cgit v1.3.1 From f557cf08b974c359ad3c53a87297d19fe13ff4f0 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 29 Dec 2022 10:50:54 +0100 Subject: efi_loader: use u16_strlen() in efi_var_mem_ins() Don't duplicate library functionality. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_var_mem.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_var_mem.c b/lib/efi_loader/efi_var_mem.c index 0bac594e004..e1058e3c6aa 100644 --- a/lib/efi_loader/efi_var_mem.c +++ b/lib/efi_loader/efi_var_mem.c @@ -146,9 +146,7 @@ efi_status_t __efi_runtime efi_var_mem_ins( var = (struct efi_var_entry *) ((uintptr_t)efi_var_buf + efi_var_buf->length); - for (var_name_len = 0; variable_name[var_name_len]; ++var_name_len) - ; - ++var_name_len; + var_name_len = u16_strlen(variable_name) + 1; data = var->name + var_name_len; if ((uintptr_t)data - (uintptr_t)efi_var_buf + size1 + size2 > -- cgit v1.3.1