blob: 244146a2be4b654b35662ee31f4347490ff0119e [file] [log] [blame]
Brad Bishopbec4ebc2022-08-03 09:55:16 -04001From 55fc3dbfb0ec21b1239808d0dddae14fbb8bb5f3 Mon Sep 17 00:00:00 2001
2From: Gowtham Suresh Kumar <gowtham.sureshkumar@arm.com>
3Date: Mon, 20 Dec 2021 19:56:30 +0000
4Subject: [PATCH] Add missing features to setVariable()
5
6This patch resolves the failing tests in SCT related to
7setVariable() function. The existing implementation is
8missing few cases where error codes are returned when called
9with certain paramters. These conditions are implemented in
10this patch based on the explanation provided in uefi spec.
11
12Upstream-Status: Pending [Not submitted to upstream yet]
13Signed-off-by: Gowtham Suresh Kumar <gowtham.sureshkumar@arm.com>
14
15
16---
17 .../backend/uefi_variable_store.c | 29 ++++++++++++++++---
18 1 file changed, 25 insertions(+), 4 deletions(-)
19
20diff --git a/components/service/smm_variable/backend/uefi_variable_store.c b/components/service/smm_variable/backend/uefi_variable_store.c
21index 1bb869ae..a1671074 100644
22--- a/components/service/smm_variable/backend/uefi_variable_store.c
23+++ b/components/service/smm_variable/backend/uefi_variable_store.c
24@@ -161,6 +161,17 @@ efi_status_t uefi_variable_store_set_variable(
25 bool should_sync_index = false;
26
27 if (status != EFI_SUCCESS) return status;
28+
29+ /*
30+ * Runtime access to a data variable implies boot service access. Attributes that have
31+ * EFI_VARIABLE_RUNTIME_ACCESS set must also have EFI_VARIABLE_BOOTSERVICE_ACCESS set.
32+ * The caller is responsible for following this rule.
33+ */
34+ if((var->Attributes & EFI_VARIABLE_RUNTIME_ACCESS))
35+ {
36+ if((var->Attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS) != EFI_VARIABLE_BOOTSERVICE_ACCESS )
37+ return EFI_INVALID_PARAMETER;
38+ }
39
40 /* Find in index */
41 const struct variable_info *info = variable_index_find(
42@@ -221,6 +232,13 @@ efi_status_t uefi_variable_store_set_variable(
43 if (!info) status = EFI_OUT_OF_RESOURCES;
44 should_sync_index = info && (info->metadata.attributes & EFI_VARIABLE_NON_VOLATILE);
45 }
46+ else
47+ {
48+ /* Return EFI_NOT_FOUND when a remove operation is performed
49+ * on variable that is not existing.
50+ */
51+ status = EFI_NOT_FOUND;
52+ }
53
54 /* The order of these operations is important. For an update
55 * or create operation, The variable index is always synchronized
56@@ -555,10 +573,13 @@ static efi_status_t check_access_permitted_on_set(
57 if ((status == EFI_SUCCESS) && var->DataSize) {
58
59 /* Restrict which attributes can be modified for an existing variable */
60- if ((var->Attributes & EFI_VARIABLE_NON_VOLATILE) !=
61- (info->metadata.attributes & EFI_VARIABLE_NON_VOLATILE)) {
62-
63- /* Don't permit change of storage class */
64+ if (((var->Attributes & EFI_VARIABLE_NON_VOLATILE) !=
65+ (info->metadata.attributes & EFI_VARIABLE_NON_VOLATILE)) ||
66+ ((var->Attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS) !=
67+ (info->metadata.attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS)) ||
68+ ((var->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) !=
69+ (info->metadata.attributes & EFI_VARIABLE_RUNTIME_ACCESS))) {
70+ /* Don't permit change of attributes */
71 status = EFI_INVALID_PARAMETER;
72 }
73 }