blob: 244146a2be4b654b35662ee31f4347490ff0119e [file] [log] [blame]
From 55fc3dbfb0ec21b1239808d0dddae14fbb8bb5f3 Mon Sep 17 00:00:00 2001
From: Gowtham Suresh Kumar <gowtham.sureshkumar@arm.com>
Date: Mon, 20 Dec 2021 19:56:30 +0000
Subject: [PATCH] Add missing features to setVariable()
This patch resolves the failing tests in SCT related to
setVariable() function. The existing implementation is
missing few cases where error codes are returned when called
with certain paramters. These conditions are implemented in
this patch based on the explanation provided in uefi spec.
Upstream-Status: Pending [Not submitted to upstream yet]
Signed-off-by: Gowtham Suresh Kumar <gowtham.sureshkumar@arm.com>
---
.../backend/uefi_variable_store.c | 29 ++++++++++++++++---
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/components/service/smm_variable/backend/uefi_variable_store.c b/components/service/smm_variable/backend/uefi_variable_store.c
index 1bb869ae..a1671074 100644
--- a/components/service/smm_variable/backend/uefi_variable_store.c
+++ b/components/service/smm_variable/backend/uefi_variable_store.c
@@ -161,6 +161,17 @@ efi_status_t uefi_variable_store_set_variable(
bool should_sync_index = false;
if (status != EFI_SUCCESS) return status;
+
+ /*
+ * Runtime access to a data variable implies boot service access. Attributes that have
+ * EFI_VARIABLE_RUNTIME_ACCESS set must also have EFI_VARIABLE_BOOTSERVICE_ACCESS set.
+ * The caller is responsible for following this rule.
+ */
+ if((var->Attributes & EFI_VARIABLE_RUNTIME_ACCESS))
+ {
+ if((var->Attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS) != EFI_VARIABLE_BOOTSERVICE_ACCESS )
+ return EFI_INVALID_PARAMETER;
+ }
/* Find in index */
const struct variable_info *info = variable_index_find(
@@ -221,6 +232,13 @@ efi_status_t uefi_variable_store_set_variable(
if (!info) status = EFI_OUT_OF_RESOURCES;
should_sync_index = info && (info->metadata.attributes & EFI_VARIABLE_NON_VOLATILE);
}
+ else
+ {
+ /* Return EFI_NOT_FOUND when a remove operation is performed
+ * on variable that is not existing.
+ */
+ status = EFI_NOT_FOUND;
+ }
/* The order of these operations is important. For an update
* or create operation, The variable index is always synchronized
@@ -555,10 +573,13 @@ static efi_status_t check_access_permitted_on_set(
if ((status == EFI_SUCCESS) && var->DataSize) {
/* Restrict which attributes can be modified for an existing variable */
- if ((var->Attributes & EFI_VARIABLE_NON_VOLATILE) !=
- (info->metadata.attributes & EFI_VARIABLE_NON_VOLATILE)) {
-
- /* Don't permit change of storage class */
+ if (((var->Attributes & EFI_VARIABLE_NON_VOLATILE) !=
+ (info->metadata.attributes & EFI_VARIABLE_NON_VOLATILE)) ||
+ ((var->Attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS) !=
+ (info->metadata.attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS)) ||
+ ((var->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) !=
+ (info->metadata.attributes & EFI_VARIABLE_RUNTIME_ACCESS))) {
+ /* Don't permit change of attributes */
status = EFI_INVALID_PARAMETER;
}
}