Skip to contentSkip to conversation

efi_loader: check query_variable_info attributes

PATCH New Vincent Stehlé 2 participants 2 messages Apr 29, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi_loader: check query_variable_info attributes

QueryVariableInfo() must return EFI_INVALID_PARAMETER when an invalid combination of attribute bits is supplied.

This fixes three SCT QueryVariableInfo_Conf failures.

Cc Heinrich Schuchardt <[email protected]>
Cc Alexander Graf <[email protected]>

Changes since v1:
- Remove if/else and return directly

---
 lib/efi_loader/efi_var_common.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/efi_loader/efi_var_common.c +4 -0
index b11ed91a74a..cbf8685fad5 100644
@@ -160,6 +160,10 @@ efi_status_t EFIAPI efi_query_variable_info(
 	EFI_ENTRY("%x %p %p %p", attributes, maximum_variable_storage_size,
 		  remaining_variable_storage_size, maximum_variable_size);
 
+	if (!attributes || ((attributes & EFI_VARIABLE_RUNTIME_ACCESS) &&
+			    !(attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS)))
+		return EFI_EXIT(EFI_INVALID_PARAMETER);
+
 	ret = efi_query_variable_info_int(attributes,
 					  maximum_variable_storage_size,
 					  remaining_variable_storage_size,
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/1 efi_loader: check query_variable_info attributes

Quoted 21 lines · Vincent Stehl?

QueryVariableInfo() must return EFI_INVALID_PARAMETER when an invalid combination of attribute bits is supplied.

This fixes three SCT QueryVariableInfo_Conf failures.

Cc Heinrich Schuchardt <[email protected]>
Cc Alexander Graf <[email protected]>

Changes since v1:
- Remove if/else and return directly

---
  lib/efi_loader/efi_var_common.c | 4 ++++
  1 file changed, 4 insertions(+)
lib/efi_loader/efi_var_common.c +0 -0
index b11ed91a74a..cbf8685fad5 100644

lib/efi_loader/efi_var_common.c efi_status_t EFIAPI efi_query_variable_info( · line 165

Quoted 6 lines
lib/efi_loader/efi_var_common.c +3 -0
@@ -160,6 +160,10 @@ efi_status_t EFIAPI efi_query_variable_info(
  	EFI_ENTRY("%x %p %p %p", attributes, maximum_variable_storage_size,
  		  remaining_variable_storage_size, maximum_variable_size);
 
+	if (!attributes || ((attributes & EFI_VARIABLE_RUNTIME_ACCESS) &&
+			    !(attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS)))
+		return EFI_EXIT(EFI_INVALID_PARAMETER);

Thank you for looking into closing this UEFI compliance gap.

The checks must be executed at runtime too. efi_query_variable_info() only covers boot time.

StandaloneMM has its own check in RuntimeServiceQueryVariableInfo(). That function only checks that attributes is non-zero. If you consider that check wrong, you would have to fix it there.

Your U-Boot side checks should be put into efi_query_variable_info_int().

Why should we consider the following values valid?

     attributes == EFI_VARIABLE_APPEND_WRITE
     attributes == EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
     attributes == EFI_VARIABLE_HARDWARE_ERROR_RECORD
     attributes == 0xffffff00

EFI_VARIABLE_APPEND_WRITE shall be ignored according to chapter 8.2 "Variable Services". Shouldn't we remove the bit before checking the remaining value?

EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS for a variable that is neither BS nor RT makes little sense.

According to chapter 8.2.4.2, "Hardware Error Record Variables" a hardware error variable must be NV, BS, RT, HR.

0xffffff00 has bits set that can never appear in attributes.

efi_set_variable_int() would also accept some invalid combinations of flags. You could try to extract a common function for checking.

Best regards

Heinrich

Quoted 5 lines
lib/efi_loader/efi_var_common.c +1 -0
+
  	ret = efi_query_variable_info_int(attributes,
  					  maximum_variable_storage_size,
  					  remaining_variable_storage_size,