blob: da3ddaf63e94d41a518b0867572078e8822f73d2 [file] [log] [blame]
Brad Bishopbec4ebc2022-08-03 09:55:16 -04001From 571ddac16048dfba4b25b04fe5cbd706c392b5ba Mon Sep 17 00:00:00 2001
2From: Vishnu Banavath <vishnu.banavath@arm.com>
3Date: Fri, 24 Dec 2021 19:17:17 +0000
4Subject: [PATCH] smm_gateway: add checks for null attributes
5
6As par EDK-2 and EDK-2 test code, when a user issue's
7setVariable() with 0 in attributes field, it means a variable
8delete request. Currently, smm gatway doesn't handle this scenario.
9This change is to add that support
10
11Signed-off-by: Vishnu Banavath <vishnu.banavath@arm.com>
12
13Upstream-Status: Pending [Not submitted to upstream yet]
14Signed-off-by: Vishnu Banavath <vishnu.banavath@arm.com>
15
16
17---
18 .../backend/uefi_variable_store.c | 28 ++++++++++++-------
19 1 file changed, 18 insertions(+), 10 deletions(-)
20
21diff --git a/components/service/smm_variable/backend/uefi_variable_store.c b/components/service/smm_variable/backend/uefi_variable_store.c
22index a57b3346..e8771c21 100644
23--- a/components/service/smm_variable/backend/uefi_variable_store.c
24+++ b/components/service/smm_variable/backend/uefi_variable_store.c
25@@ -167,7 +167,9 @@ efi_status_t uefi_variable_store_set_variable(
26 * EFI_VARIABLE_RUNTIME_ACCESS set must also have EFI_VARIABLE_BOOTSERVICE_ACCESS set.
27 * The caller is responsible for following this rule.
28 */
29- if((var->Attributes & EFI_VARIABLE_RUNTIME_ACCESS))
30+ if (!var->Attributes)
31+ EMSG("It might be a delete variable request\n");
32+ else if((var->Attributes & EFI_VARIABLE_RUNTIME_ACCESS))
33 {
34 if((var->Attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS) != EFI_VARIABLE_BOOTSERVICE_ACCESS )
35 return EFI_INVALID_PARAMETER;
36@@ -191,7 +193,7 @@ efi_status_t uefi_variable_store_set_variable(
37 (var->Attributes & EFI_VARIABLE_NON_VOLATILE) ||
38 (info->is_variable_set && (info->metadata.attributes & EFI_VARIABLE_NON_VOLATILE));
39
40- if (var->DataSize) {
41+ if (var->DataSize && var->Attributes) {
42
43 /* It's a set rather than a remove operation */
44 variable_index_update_variable(
45@@ -206,7 +208,9 @@ efi_status_t uefi_variable_store_set_variable(
46 * that it's never possible for an object to exist within
47 * the storage backend without a corresponding index entry.
48 */
49- remove_variable_data(context, info);
50+ EMSG(" deleting variable %s \n",var->Name);
51+ if (remove_variable_data(context, info) != PSA_SUCCESS)
52+ EMSG(" deleting variable %s FAILED\n",var->Name);
53 variable_index_remove_variable(&context->variable_index, info);
54
55 /* Variable info no longer valid */
56@@ -587,14 +591,18 @@ static efi_status_t check_access_permitted_on_set(
57 }
58
59 if ((status == EFI_SUCCESS) && var->DataSize) {
60-
61+ /* Delete the variable with Attributes is 0 */
62+ if (!var->Attributes) {
63+ EMSG("Null attributes, may be a delete variable request\n");
64+ status = EFI_SUCCESS;
65+ }
66 /* Restrict which attributes can be modified for an existing variable */
67- if (((var->Attributes & EFI_VARIABLE_NON_VOLATILE) !=
68- (info->metadata.attributes & EFI_VARIABLE_NON_VOLATILE)) ||
69- ((var->Attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS) !=
70- (info->metadata.attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS)) ||
71- ((var->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) !=
72- (info->metadata.attributes & EFI_VARIABLE_RUNTIME_ACCESS))) {
73+ else if (((var->Attributes & EFI_VARIABLE_NON_VOLATILE) !=
74+ (info->metadata.attributes & EFI_VARIABLE_NON_VOLATILE)) ||
75+ ((var->Attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS) !=
76+ (info->metadata.attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS)) ||
77+ ((var->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) !=
78+ (info->metadata.attributes & EFI_VARIABLE_RUNTIME_ACCESS))) {
79 /* Don't permit change of attributes */
80 status = EFI_INVALID_PARAMETER;
81 }