]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/Variable: Make only EFI_VARIABLE_NON_VOLATILE invalid
authorSunny Wang <Sunny.Wang@arm.com>
Tue, 11 Jan 2022 21:37:20 +0000 (05:37 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 21 Jan 2022 02:13:31 +0000 (02:13 +0000)
Only EFI_VARIABLE_NON_VOLATILE attribute is an invalid combination
of attribute bits, so update the variable driver to return
EFI_INVALID_PARAMETER so that we can prevent the invalid variable
being created.

This change also fixes the SCT failure below:
 - RT.QueryVariableInfo - With being an invalid combination -- FAILURE

For details, please check the threads below:
 - https://edk2.groups.io/g/devel/topic/86486174
 - https://edk2.groups.io/g/devel/message/82466

Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Cc: G Edhaya Chandran <edhaya.chandran@arm.com>
Cc: Samer El-Haj-Mahmoud <samer.el-haj-mahmoud@arm.com>
Signed-off-by: Sunny Wang <sunny.wang@arm.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c

index 9722a944201865d56dd3af20788f5dfe727821e1..6c1a3440ac8cf5abe085e451fe15d857f25db3f4 100644 (file)
@@ -19,6 +19,7 @@
 Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2015-2018 Hewlett Packard Enterprise Development LP<BR>\r
 Copyright (c) Microsoft Corporation.<BR>\r
+Copyright (c) 2022, ARM Limited. All rights reserved.<BR>\r
 \r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -2660,14 +2661,22 @@ VariableServiceSetVariable (
   }\r
 \r
   //\r
-  //  Make sure if runtime bit is set, boot service bit is set also.\r
+  // Check if the combination of attribute bits is valid.\r
   //\r
   if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {\r
+    //\r
+    // Make sure if runtime bit is set, boot service bit is set also.\r
+    //\r
     if ((Attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) != 0) {\r
       return EFI_UNSUPPORTED;\r
     } else {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
+  } else if ((Attributes & EFI_VARIABLE_ATTRIBUTES_MASK) == EFI_VARIABLE_NON_VOLATILE) {\r
+    //\r
+    // Only EFI_VARIABLE_NON_VOLATILE attribute is invalid\r
+    //\r
+    return EFI_INVALID_PARAMETER;\r
   } else if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) != 0) {\r
     if (!mVariableModuleGlobal->VariableGlobal.AuthSupport) {\r
       //\r
@@ -3142,6 +3151,11 @@ VariableServiceQueryVariableInfo (
     // Make sure the Attributes combination is supported by the platform.\r
     //\r
     return EFI_UNSUPPORTED;\r
+  } else if ((Attributes & EFI_VARIABLE_ATTRIBUTES_MASK) == EFI_VARIABLE_NON_VOLATILE) {\r
+    //\r
+    // Only EFI_VARIABLE_NON_VOLATILE attribute is invalid\r
+    //\r
+    return EFI_INVALID_PARAMETER;\r
   } else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS) {\r
     //\r
     // Make sure if runtime bit is set, boot service bit is set also.\r