Skip to contentSkip to conversation

efi_loader: Fix UEFI variable error handling

PATCH RESEND In review Weizhao Ouyang 2 participants 3 messages Nov 13, 2023 – Nov 15, 2023

lore
Share & tools
lore
#0 lore raw

PATCH RESEND v2 1/1 efi_loader: Fix UEFI variable error handling

Try to catch error the earlier way.

---
 lib/efi_loader/efi_var_file.c | 4 +++-
 lib/efi_loader/efi_variable.c | 2 --
 2 files changed, 3 insertions(+), 3 deletions(-)
lib/efi_loader/efi_var_file.c +3 -1
index 62e071bd83..fe1c462f17 100644
@@ -192,8 +192,10 @@ efi_status_t efi_var_restore(struct efi_var_file *buf, bool safe)
 		ret = efi_var_mem_ins(var->name, &var->guid, var->attr,
 				      var->length, data, 0, NULL,
 				      var->time);
-		if (ret != EFI_SUCCESS)
+		if (ret != EFI_SUCCESS) {
 			log_err("Failed to set EFI variable %ls\n", var->name);
+			return ret;
+		}
 	}
 	return EFI_SUCCESS;
 }
lib/efi_loader/efi_variable.c +0 -2
index be95ed44e6..2b2ca8c090 100644
@@ -350,8 +350,6 @@ efi_status_t efi_set_variable_int(const u16 *variable_name,
 
 	if (var_type == EFI_AUTH_VAR_PK)
 		ret = efi_init_secure_state();
-	else
-		ret = EFI_SUCCESS;
 
 	/*
 	 * Write non-volatile EFI variables to file
Signature · 1 line
2.39.2
#1 lore raw
Quoted 13 lines · Weizhao Ouyang

Try to catch error the earlier way.

---
  lib/efi_loader/efi_var_file.c | 4 +++-
  lib/efi_loader/efi_variable.c | 2 --
  2 files changed, 3 insertions(+), 3 deletions(-)
lib/efi_loader/efi_var_file.c +0 -0
index 62e071bd83..fe1c462f17 100644

lib/efi_loader/efi_var_file.c efi_status_t efi_var_restore(struct efi_var_file *buf, bool safe) · line 197

Quoted 7 lines
lib/efi_loader/efi_var_file.c +2 -1
@@ -192,8 +192,10 @@ efi_status_t efi_var_restore(struct efi_var_file *buf, bool safe)
  		ret = efi_var_mem_ins(var->name, &var->guid, var->attr,
  				      var->length, data, 0, NULL,
  				      var->time);
-		if (ret != EFI_SUCCESS)
+		if (ret != EFI_SUCCESS) {
  			log_err("Failed to set EFI variable %ls\n", var->name);
+			return ret;

This change implies that if a failure occurs, initialization of the EFI sub-system fails and you will not be able to boot via EFI.

Such a failure will occur if ubootefi.var contains more variables than fit into the memory buffer.

Please, describe why you want to disable U-Boot's EFI sub-system in this case.

Quoted 9 lines
lib/efi_loader/efi_var_file.c +1 -0
+		}
  	}
  	return EFI_SUCCESS;
  }
lib/efi_loader/efi_variable.c +0 -0
index be95ed44e6..2b2ca8c090 100644

lib/efi_loader/efi_variable.c efi_status_t efi_set_variable_int(const u16 *variable_name, · line 354

Quoted 5 lines
lib/efi_loader/efi_variable.c +0 -2
@@ -350,8 +350,6 @@ efi_status_t efi_set_variable_int(const u16 *variable_name,
 
  	if (var_type == EFI_AUTH_VAR_PK)
  		ret = efi_init_secure_state();
-	else
-		ret = EFI_SUCCESS;

This change is ok.

Best regards

Heinrich

Quoted 3 lines
lib/efi_loader/efi_variable.c +0 -0
  	/*
  	 * Write non-volatile EFI variables to file
#2 lore raw
Quoted 26 lines · Heinrich Schuchardt
Quoted 13 lines · Weizhao Ouyang

Try to catch error the earlier way.

---
  lib/efi_loader/efi_var_file.c | 4 +++-
  lib/efi_loader/efi_variable.c | 2 --
  2 files changed, 3 insertions(+), 3 deletions(-)
lib/efi_loader/efi_var_file.c +0 -0
index 62e071bd83..fe1c462f17 100644

lib/efi_loader/efi_var_file.c efi_status_t efi_var_restore(struct efi_var_file *buf, bool safe) · line 197

Quoted 7 lines
lib/efi_loader/efi_var_file.c +2 -1
@@ -192,8 +192,10 @@ efi_status_t efi_var_restore(struct efi_var_file *buf, bool safe)
              ret = efi_var_mem_ins(var->name, &var->guid, var->attr,
                                    var->length, data, 0, NULL,
                                    var->time);
-             if (ret != EFI_SUCCESS)
+             if (ret != EFI_SUCCESS) {
                      log_err("Failed to set EFI variable %ls\n", var->name);
+                     return ret;

This change implies that if a failure occurs, initialization of the EFI sub-system fails and you will not be able to boot via EFI.

Quoted 5 lines

Such a failure will occur if ubootefi.var contains more variables than fit into the memory buffer.

Please, describe why you want to disable U-Boot's EFI sub-system in this case.

Hi Heinrich,

In my case, if a variable wants to persist as a non-volatile variable to ubootefi.var, we should keep the same behavior as runtime variable does. Otherwise the ubootefi.var cannot be trusted.

BR,
Weizhao

Quoted 26 lines
Quoted 10 lines
lib/efi_loader/efi_var_file.c +1 -0
+             }
      }
      return EFI_SUCCESS;
  }
lib/efi_loader/efi_variable.c +0 -0
index be95ed44e6..2b2ca8c090 100644

lib/efi_loader/efi_variable.c efi_status_t efi_set_variable_int(const u16 *variable_name, · line 354

Quoted 5 lines
lib/efi_loader/efi_variable.c +0 -2
@@ -350,8 +350,6 @@ efi_status_t efi_set_variable_int(const u16 *variable_name,
 
      if (var_type == EFI_AUTH_VAR_PK)
              ret = efi_init_secure_state();
-     else
-             ret = EFI_SUCCESS;

This change is ok.

Best regards

Heinrich

Quoted 3 lines
lib/efi_loader/efi_variable.c +0 -0
      /*
       * Write non-volatile EFI variables to file