]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg/MdeModulePkg/SecurityPkg Variable: Forbid creation of non-spec variables in...
authorStar Zeng <star.zeng@intel.com>
Mon, 19 Aug 2013 05:16:45 +0000 (05:16 +0000)
committerlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 19 Aug 2013 05:16:45 +0000 (05:16 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14560 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h
MdePkg/Include/Guid/GlobalVariable.h
MdePkg/Include/Guid/ImageAuthentication.h
MdePkg/Include/Uefi/UefiSpec.h
SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c
SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.h

index d31fe0c871d634e24fbf29f0bc94590165fc60f0..51dd0fd6f72f41216727b65b3d4e8c597ee45f21 100644 (file)
@@ -44,6 +44,51 @@ BOOLEAN                mEndOfDxe              = FALSE;
 ///\r
 BOOLEAN                mEnableLocking         = TRUE;\r
 \r
+//\r
+// To prevent name collisions with possible future globally defined variables,\r
+// other internal firmware data variables that are not defined here must be\r
+// saved with a unique VendorGuid other than EFI_GLOBAL_VARIABLE or\r
+// any other GUID defined by the UEFI Specification. Implementations must\r
+// only permit the creation of variables with a UEFI Specification-defined\r
+// VendorGuid when these variables are documented in the UEFI Specification.\r
+//\r
+GLOBAL_VARIABLE_ENTRY mGlobalVariableList[] = {\r
+  {EFI_LANG_CODES_VARIABLE_NAME,             VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_LANG_VARIABLE_NAME,                   VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_TIME_OUT_VARIABLE_NAME,               VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_PLATFORM_LANG_CODES_VARIABLE_NAME,    VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_PLATFORM_LANG_VARIABLE_NAME,          VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_CON_IN_VARIABLE_NAME,                 VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_CON_OUT_VARIABLE_NAME,                VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_ERR_OUT_VARIABLE_NAME,                VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_CON_IN_DEV_VARIABLE_NAME,             VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_CON_OUT_DEV_VARIABLE_NAME,            VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_ERR_OUT_DEV_VARIABLE_NAME,            VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_BOOT_ORDER_VARIABLE_NAME,             VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_BOOT_NEXT_VARIABLE_NAME,              VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_BOOT_CURRENT_VARIABLE_NAME,           VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME,    VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_DRIVER_ORDER_VARIABLE_NAME,           VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_HW_ERR_REC_SUPPORT_VARIABLE_NAME,     VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_SETUP_MODE_NAME,                      VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_KEY_EXCHANGE_KEY_NAME,                VARIABLE_ATTRIBUTE_NV_BS_RT_AT},\r
+  {EFI_PLATFORM_KEY_NAME,                    VARIABLE_ATTRIBUTE_NV_BS_RT_AT},\r
+  {EFI_SIGNATURE_SUPPORT_NAME,               VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_SECURE_BOOT_MODE_NAME,                VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_KEK_DEFAULT_VARIABLE_NAME,            VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_PK_DEFAULT_VARIABLE_NAME,             VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_DB_DEFAULT_VARIABLE_NAME,             VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_DBX_DEFAULT_VARIABLE_NAME,            VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_DBT_DEFAULT_VARIABLE_NAME,            VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME, VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_OS_INDICATIONS_VARIABLE_NAME,         VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_VENDOR_KEYS_VARIABLE_NAME,            VARIABLE_ATTRIBUTE_BS_RT},\r
+};\r
+GLOBAL_VARIABLE_ENTRY mGlobalVariableList2[] = {\r
+  {L"Boot####",                              VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {L"Driver####",                            VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {L"Key####",                               VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+};\r
 \r
 /**\r
   Routine used to track statistical information about variable usage. \r
@@ -1236,7 +1281,7 @@ AutoUpdateLangVariable (
 \r
   SetLanguageCodes = FALSE;\r
 \r
-  if (StrCmp (VariableName, L"PlatformLangCodes") == 0) {\r
+  if (StrCmp (VariableName, EFI_PLATFORM_LANG_CODES_VARIABLE_NAME) == 0) {\r
     //\r
     // PlatformLangCodes is a volatile variable, so it can not be updated at runtime.\r
     //\r
@@ -1266,7 +1311,7 @@ AutoUpdateLangVariable (
     mVariableModuleGlobal->PlatformLang = AllocateRuntimePool (DataSize);\r
     ASSERT (mVariableModuleGlobal->PlatformLang != NULL);\r
 \r
-  } else if (StrCmp (VariableName, L"LangCodes") == 0) {\r
+  } else if (StrCmp (VariableName, EFI_LANG_CODES_VARIABLE_NAME) == 0) {\r
     //\r
     // LangCodes is a volatile variable, so it can not be updated at runtime.\r
     //\r
@@ -1294,21 +1339,21 @@ AutoUpdateLangVariable (
     // Update Lang if PlatformLang is already set\r
     // Update PlatformLang if Lang is already set\r
     //\r
-    Status = FindVariable (L"PlatformLang", &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
+    Status = FindVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
     if (!EFI_ERROR (Status)) {\r
       //\r
       // Update Lang\r
       //\r
-      VariableName = L"PlatformLang";\r
+      VariableName = EFI_PLATFORM_LANG_VARIABLE_NAME;\r
       Data         = GetVariableDataPtr (Variable.CurrPtr);\r
       DataSize     = Variable.CurrPtr->DataSize;\r
     } else {\r
-      Status = FindVariable (L"Lang", &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
+      Status = FindVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
       if (!EFI_ERROR (Status)) {\r
         //\r
         // Update PlatformLang\r
         //\r
-        VariableName = L"Lang";\r
+        VariableName = EFI_LANG_VARIABLE_NAME;\r
         Data         = GetVariableDataPtr (Variable.CurrPtr);\r
         DataSize     = Variable.CurrPtr->DataSize;\r
       } else {\r
@@ -1325,7 +1370,7 @@ AutoUpdateLangVariable (
   //\r
   Attributes = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;\r
 \r
-  if (StrCmp (VariableName, L"PlatformLang") == 0) {\r
+  if (StrCmp (VariableName, EFI_PLATFORM_LANG_VARIABLE_NAME) == 0) {\r
     //\r
     // Update Lang when PlatformLangCodes/LangCodes were set.\r
     //\r
@@ -1348,9 +1393,9 @@ AutoUpdateLangVariable (
         //\r
         // Successfully convert PlatformLang to Lang, and set the BestLang value into Lang variable simultaneously.\r
         //\r
-        FindVariable (L"Lang", &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
+        FindVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
 \r
-        Status = UpdateVariable (L"Lang", &gEfiGlobalVariableGuid, BestLang,\r
+        Status = UpdateVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestLang,\r
                                  ISO_639_2_ENTRY_SIZE + 1, Attributes, &Variable);\r
 \r
         DEBUG ((EFI_D_INFO, "Variable Driver Auto Update PlatformLang, PlatformLang:%a, Lang:%a\n", BestPlatformLang, BestLang));\r
@@ -1359,7 +1404,7 @@ AutoUpdateLangVariable (
       }\r
     }\r
 \r
-  } else if (StrCmp (VariableName, L"Lang") == 0) {\r
+  } else if (StrCmp (VariableName, EFI_LANG_VARIABLE_NAME) == 0) {\r
     //\r
     // Update PlatformLang when PlatformLangCodes/LangCodes were set.\r
     //\r
@@ -1382,9 +1427,9 @@ AutoUpdateLangVariable (
         //\r
         // Successfully convert Lang to PlatformLang, and set the BestPlatformLang value into PlatformLang variable simultaneously.\r
         //\r
-        FindVariable (L"PlatformLang", &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
+        FindVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
 \r
-        Status = UpdateVariable (L"PlatformLang", &gEfiGlobalVariableGuid, BestPlatformLang, \r
+        Status = UpdateVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestPlatformLang, \r
                                  AsciiStrSize (BestPlatformLang), Attributes, &Variable);\r
 \r
         DEBUG ((EFI_D_INFO, "Variable Driver Auto Update Lang, Lang:%a, PlatformLang:%a\n", BestLang, BestPlatformLang));\r
@@ -1934,6 +1979,63 @@ IsHwErrRecVariable (
   return TRUE;\r
 }\r
 \r
+/**\r
+  This code checks if variable guid is global variable guid first.\r
+  If yes, further check if variable name is in mGlobalVariableList or mGlobalVariableList2 and attributes matched.\r
+\r
+  @param[in] VariableName       Pointer to variable name.\r
+  @param[in] VendorGuid         Variable Vendor Guid.\r
+  @param[in] Attributes         Attributes of the variable.\r
+\r
+  @retval EFI_SUCCESS           Variable is not global variable, or Variable is global variable, variable name is in the lists and attributes matched.\r
+  @retval EFI_INVALID_PARAMETER Variable is global variable, but variable name is not in the lists or attributes unmatched.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CheckEfiGlobalVariable (\r
+  IN CHAR16             *VariableName,\r
+  IN EFI_GUID           *VendorGuid,\r
+  IN UINT32             Attributes\r
+  )\r
+{\r
+  UINTN     Index;\r
+  UINTN     NameLength;\r
+\r
+  if (CompareGuid (VendorGuid, &gEfiGlobalVariableGuid)){\r
+    //\r
+    // Try list 1, exactly match.\r
+    //\r
+    for (Index = 0; Index < sizeof (mGlobalVariableList)/sizeof (mGlobalVariableList[0]); Index++) {\r
+      if ((StrCmp (mGlobalVariableList[Index].Name, VariableName) == 0) &&\r
+          (Attributes == 0 || Attributes == mGlobalVariableList[Index].Attributes)) {\r
+        return EFI_SUCCESS;\r
+      }\r
+    }\r
+\r
+    //\r
+    // Try list 2.\r
+    //\r
+    NameLength = StrLen (VariableName) - 4;\r
+    for (Index = 0; Index < sizeof (mGlobalVariableList2)/sizeof (mGlobalVariableList2[0]); Index++) {\r
+      if ((StrLen (VariableName) == StrLen (mGlobalVariableList2[Index].Name)) &&\r
+          (StrnCmp (mGlobalVariableList2[Index].Name, VariableName, NameLength) == 0) &&\r
+          IsHexaDecimalDigitCharacter (VariableName[NameLength]) &&\r
+          IsHexaDecimalDigitCharacter (VariableName[NameLength + 1]) &&\r
+          IsHexaDecimalDigitCharacter (VariableName[NameLength + 2]) &&\r
+          IsHexaDecimalDigitCharacter (VariableName[NameLength + 3]) &&\r
+          (Attributes == 0 || Attributes == mGlobalVariableList2[Index].Attributes)) {\r
+        return EFI_SUCCESS;\r
+      }\r
+    }\r
+\r
+    DEBUG ((EFI_D_INFO, "[Variable]: set global variable with invalid variable name or attributes - %g:%s:%x\n", VendorGuid, VariableName, Attributes));\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 /**\r
   Mark a variable that will become read-only after leaving the DXE phase of execution.\r
 \r
@@ -2317,6 +2419,11 @@ VariableServiceSetVariable (
     }  \r
   }\r
 \r
+  Status = CheckEfiGlobalVariable (VariableName, VendorGuid, Attributes);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
   AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
 \r
   //\r
index 264a2396c61a25603eecab35cc9fe9500d9f6a5d..a10ad8755a2dfb767387950d51582dc2f874896a 100644 (file)
@@ -42,7 +42,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Guid/FaultTolerantWrite.h>\r
 #include <Guid/HardwareErrorVariable.h>\r
 \r
-#define VARIABLE_RECLAIM_THRESHOLD (1024)\r
+#define VARIABLE_ATTRIBUTE_BS_RT        (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS)\r
+#define VARIABLE_ATTRIBUTE_NV_BS_RT     (VARIABLE_ATTRIBUTE_BS_RT | EFI_VARIABLE_NON_VOLATILE)\r
+#define VARIABLE_ATTRIBUTE_NV_BS_RT_AT  (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS)\r
+\r
+typedef struct {\r
+  CHAR16      *Name;\r
+  UINT32      Attributes;\r
+} GLOBAL_VARIABLE_ENTRY;\r
 \r
 ///\r
 /// The size of a 3 character ISO639 language code.\r
index 0f1c173f63f605cd271634620ee835ff284e537c..83450da8575c627c6610ff142fdae4d30ad670c3 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   GUID for EFI (NVRAM) Variables.\r
 \r
-  Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials                          \r
   are licensed and made available under the terms and conditions of the BSD License         \r
   which accompanies this distribution.  The full text of the license may be found at        \r
 \r
 extern EFI_GUID gEfiGlobalVariableGuid;\r
 \r
+//\r
+// Follow UEFI 2.4 spec:\r
+// To prevent name collisions with possible future globally defined variables,\r
+// other internal firmware data variables that are not defined here must be\r
+// saved with a unique VendorGuid other than EFI_GLOBAL_VARIABLE or\r
+// any other GUID defined by the UEFI Specification. Implementations must\r
+// only permit the creation of variables with a UEFI Specification-defined\r
+// VendorGuid when these variables are documented in the UEFI Specification.\r
+//\r
+// Note: except the globally defined variables defined below, the spec also defines\r
+// L"Boot####"      - A boot load option.\r
+// L"Driver####"    - A driver load option.\r
+// L"Key####"       - Describes hot key relationship with a Boot#### load option.\r
+// The attribute for them is NV+BS+RT, #### is a printed hex value, and no 0x or h\r
+// is included in the hex value. They can not be expressed as a #define like other globally\r
+// defined variables, it is because we can not list the Boot0000, Boot0001, etc one by one.\r
+//\r
+\r
+///\r
+/// The language codes that the firmware supports. This value is deprecated.\r
+/// Its attribute is BS+RT.\r
+///\r
+#define EFI_LANG_CODES_VARIABLE_NAME                L"LangCodes"\r
+///\r
+/// The language code that the system is configured for. This value is deprecated.\r
+/// Its attribute is NV+BS+RT.\r
+///\r
+#define EFI_LANG_VARIABLE_NAME                      L"Lang"\r
+///\r
+/// The firmware's boot managers timeout, in seconds, before initiating the default boot selection.\r
+/// Its attribute is NV+BS+RT.\r
+///\r
+#define EFI_TIME_OUT_VARIABLE_NAME                  L"Timeout"\r
+///\r
+/// The language codes that the firmware supports.\r
+/// Its attribute is BS+RT.\r
+///\r
+#define EFI_PLATFORM_LANG_CODES_VARIABLE_NAME       L"PlatformLangCodes"\r
+///\r
+/// The language code that the system is configured for.\r
+/// Its attribute is NV+BS+RT.\r
+///\r
+#define EFI_PLATFORM_LANG_VARIABLE_NAME             L"PlatformLang"\r
+///\r
+/// The device path of the default input/output/error output console.\r
+/// Its attribute is NV+BS+RT.\r
+///\r
+#define EFI_CON_IN_VARIABLE_NAME                    L"ConIn"\r
+#define EFI_CON_OUT_VARIABLE_NAME                   L"ConOut"\r
+#define EFI_ERR_OUT_VARIABLE_NAME                   L"ErrOut"\r
+///\r
+/// The device path of all possible input/output/error output devices.\r
+/// Its attribute is BS+RT.\r
+///\r
+#define EFI_CON_IN_DEV_VARIABLE_NAME                L"ConInDev"\r
+#define EFI_CON_OUT_DEV_VARIABLE_NAME               L"ConOutDev"\r
+#define EFI_ERR_OUT_DEV_VARIABLE_NAME               L"ErrOutDev"\r
+///\r
+/// The ordered boot option load list.\r
+/// Its attribute is NV+BS+RT.\r
+///\r
+#define EFI_BOOT_ORDER_VARIABLE_NAME                L"BootOrder"\r
+///\r
+/// The boot option for the next boot only.\r
+/// Its attribute is NV+BS+RT.\r
+///\r
+#define EFI_BOOT_NEXT_VARIABLE_NAME                 L"BootNext"\r
+///\r
+/// The boot option that was selected for the current boot.\r
+/// Its attribute is BS+RT.\r
+///\r
+#define EFI_BOOT_CURRENT_VARIABLE_NAME              L"BootCurrent"\r
+///\r
+/// The types of boot options supported by the boot manager. Should be treated as read-only.\r
+/// Its attribute is BS+RT.\r
+///\r
+#define EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME       L"BootOptionSupport"\r
+///\r
+/// The ordered driver load option list.\r
+/// Its attribute is NV+BS+RT.\r
+///\r
+#define EFI_DRIVER_ORDER_VARIABLE_NAME              L"DriverOrder"\r
+///\r
+/// Identifies the level of hardware error record persistence\r
+/// support implemented by the platform. This variable is\r
+/// only modified by firmware and is read-only to the OS.\r
+/// Its attribute is NV+BS+RT.\r
+///\r
+#define EFI_HW_ERR_REC_SUPPORT_VARIABLE_NAME        L"HwErrRecSupport"\r
+///\r
+/// Whether the system is operating in setup mode (1) or not (0).\r
+/// All other values are reserved. Should be treated as read-only.\r
+/// Its attribute is BS+RT.\r
+///\r
+#define EFI_SETUP_MODE_NAME                         L"SetupMode"\r
+///\r
+/// The Key Exchange Key Signature Database.\r
+/// Its attribute is NV+BS+RT+AT.\r
+///\r
+#define EFI_KEY_EXCHANGE_KEY_NAME                   L"KEK"\r
+///\r
+/// The public Platform Key.\r
+/// Its attribute is NV+BS+RT+AT.\r
+///\r
+#define EFI_PLATFORM_KEY_NAME                       L"PK"\r
+///\r
+/// Array of GUIDs representing the type of signatures supported\r
+/// by the platform firmware. Should be treated as read-only.\r
+/// Its attribute is BS+RT.\r
+///\r
+#define EFI_SIGNATURE_SUPPORT_NAME                  L"SignatureSupport"\r
+///\r
+/// Whether the platform firmware is operating in Secure boot mode (1) or not (0).\r
+/// All other values are reserved. Should be treated as read-only.\r
+/// Its attribute is BS+RT.\r
+///\r
+#define EFI_SECURE_BOOT_MODE_NAME                   L"SecureBoot"\r
+///\r
+/// The OEM's default Key Exchange Key Signature Database. Should be treated as read-only.\r
+/// Its attribute is BS+RT.\r
+///\r
+#define EFI_KEK_DEFAULT_VARIABLE_NAME               L"KEKDefault"\r
+///\r
+/// The OEM's default public Platform Key. Should be treated as read-only.\r
+/// Its attribute is BS+RT.\r
+///\r
+#define EFI_PK_DEFAULT_VARIABLE_NAME                L"PKDefault"\r
+///\r
+/// The OEM's default secure boot signature store. Should be treated as read-only.\r
+/// Its attribute is BS+RT.\r
+///\r
+#define EFI_DB_DEFAULT_VARIABLE_NAME                L"dbDefault"\r
+///\r
+/// The OEM's default secure boot blacklist signature store. Should be treated as read-only.\r
+/// Its attribute is BS+RT.\r
+///\r
+#define EFI_DBX_DEFAULT_VARIABLE_NAME               L"dbxDefault"\r
+///\r
+/// The OEM's default secure boot timestamp signature store. Should be treated as read-only.\r
+/// Its attribute is BS+RT.\r
+///\r
+#define EFI_DBT_DEFAULT_VARIABLE_NAME               L"dbtDefault"\r
+///\r
+/// Allows the firmware to indicate supported features and actions to the OS.\r
+/// Its attribute is BS+RT.\r
+///\r
+#define EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME    L"OsIndicationsSupported"\r
+///\r
+/// Allows the OS to request the firmware to enable certain features and to take certain actions.\r
+/// Its attribute is NV+BS+RT.\r
+///\r
+#define EFI_OS_INDICATIONS_VARIABLE_NAME            L"OsIndications"\r
+///\r
+/// Whether the system is configured to use only vendor provided\r
+/// keys or not. Should be treated as read-only.\r
+/// Its attribute is BS+RT.\r
+///\r
+#define EFI_VENDOR_KEYS_VARIABLE_NAME               L"VendorKeys"\r
+\r
 #endif\r
index 634fd655be528aee0b26bdcb031fbd267812bbf8..8b46e7356b757600ff142871c456df5aa3155fcb 100644 (file)
@@ -1,8 +1,7 @@
 /** @file\r
-  Platform Key, Key Exchange Key, and Image signature database are defined \r
-  for the signed image validation.\r
+  Image signature database are defined for the signed image validation.\r
 \r
-  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials                          \r
   are licensed and made available under the terms and conditions of the BSD License         \r
   which accompanies this distribution.  The full text of the license may be found at        \r
 /// for the forbidden signature database.\r
 ///\r
 #define EFI_IMAGE_SECURITY_DATABASE1      L"dbx"\r
+\r
 #define SECURE_BOOT_MODE_ENABLE           1\r
 #define SECURE_BOOT_MODE_DISABLE          0\r
 #define SETUP_MODE                        1\r
 #define USER_MODE                         0\r
-///\r
-/// Globally "SetupMode" variable to specify whether the system is currently operating \r
-/// in setup mode (1) or not (0). All other values are reserved.\r
-///\r
-#define EFI_SETUP_MODE_NAME               L"SetupMode"\r
-///\r
-/// Globally "PK" variable for the Platform Key Signature Database.\r
-///\r
-#define EFI_PLATFORM_KEY_NAME             L"PK"\r
-///\r
-/// Globally "KEK" variable for the Key Exchange Key Signature Database.\r
-///\r
-#define EFI_KEY_EXCHANGE_KEY_NAME         L"KEK"\r
-///\r
-/// Globally "SignatureSupport" variable returns an array of GUIDs, \r
-/// with each GUID representing a type of signature which the platform \r
-/// firmware supports for images and other data.\r
-///\r
-#define EFI_SIGNATURE_SUPPORT_NAME        L"SignatureSupport"\r
 \r
-///\r
-/// Globally "SecureBoot" variable to specify whether the platform firmware \r
-/// is operating in Secure boot mode (1) or not (0). All other values are reserved.\r
-///\r
-#define EFI_SECURE_BOOT_MODE_NAME         L"SecureBoot"\r
 \r
 //***********************************************************************\r
 // Signature Database\r
index 887b68cf0558cd0d1c025d3a0b7730916e1647c1..d837d385c29c2c0df8904eb27afcf9311d48af76 100644 (file)
@@ -5,7 +5,7 @@
   If a code construct is defined in the UEFI 2.4 specification it must be included\r
   by this include file.\r
 \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available under \r
 the terms and conditions of the BSD License that accompanies this distribution.  \r
 The full text of the license may be found at\r
@@ -668,7 +668,7 @@ EFI_STATUS
 \r
   @retval EFI_SUCCESS            The firmware has successfully stored the variable and its data as\r
                                  defined by the Attributes.\r
-  @retval EFI_INVALID_PARAMETER  An invalid combination of attribute bits was supplied, or the\r
+  @retval EFI_INVALID_PARAMETER  An invalid combination of attribute bits, name, and GUID was supplied, or the\r
                                  DataSize exceeds the maximum allowed.\r
   @retval EFI_INVALID_PARAMETER  VariableName is an empty string.\r
   @retval EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the variable and its data.\r
index 53ef092aff951d9eebf3e676c229dca39c2f2bd9..5261157ff24883439ac60e79d6b2cb1ab0ffc077 100644 (file)
@@ -58,6 +58,51 @@ BOOLEAN                mEndOfDxe              = FALSE;
 ///\r
 BOOLEAN                mEnableLocking         = TRUE;\r
 \r
+//\r
+// To prevent name collisions with possible future globally defined variables,\r
+// other internal firmware data variables that are not defined here must be\r
+// saved with a unique VendorGuid other than EFI_GLOBAL_VARIABLE or\r
+// any other GUID defined by the UEFI Specification. Implementations must\r
+// only permit the creation of variables with a UEFI Specification-defined\r
+// VendorGuid when these variables are documented in the UEFI Specification.\r
+//\r
+GLOBAL_VARIABLE_ENTRY mGlobalVariableList[] = {\r
+  {EFI_LANG_CODES_VARIABLE_NAME,             VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_LANG_VARIABLE_NAME,                   VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_TIME_OUT_VARIABLE_NAME,               VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_PLATFORM_LANG_CODES_VARIABLE_NAME,    VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_PLATFORM_LANG_VARIABLE_NAME,          VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_CON_IN_VARIABLE_NAME,                 VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_CON_OUT_VARIABLE_NAME,                VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_ERR_OUT_VARIABLE_NAME,                VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_CON_IN_DEV_VARIABLE_NAME,             VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_CON_OUT_DEV_VARIABLE_NAME,            VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_ERR_OUT_DEV_VARIABLE_NAME,            VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_BOOT_ORDER_VARIABLE_NAME,             VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_BOOT_NEXT_VARIABLE_NAME,              VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_BOOT_CURRENT_VARIABLE_NAME,           VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME,    VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_DRIVER_ORDER_VARIABLE_NAME,           VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_HW_ERR_REC_SUPPORT_VARIABLE_NAME,     VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_SETUP_MODE_NAME,                      VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_KEY_EXCHANGE_KEY_NAME,                VARIABLE_ATTRIBUTE_NV_BS_RT_AT},\r
+  {EFI_PLATFORM_KEY_NAME,                    VARIABLE_ATTRIBUTE_NV_BS_RT_AT},\r
+  {EFI_SIGNATURE_SUPPORT_NAME,               VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_SECURE_BOOT_MODE_NAME,                VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_KEK_DEFAULT_VARIABLE_NAME,            VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_PK_DEFAULT_VARIABLE_NAME,             VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_DB_DEFAULT_VARIABLE_NAME,             VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_DBX_DEFAULT_VARIABLE_NAME,            VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_DBT_DEFAULT_VARIABLE_NAME,            VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME, VARIABLE_ATTRIBUTE_BS_RT},\r
+  {EFI_OS_INDICATIONS_VARIABLE_NAME,         VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {EFI_VENDOR_KEYS_VARIABLE_NAME,            VARIABLE_ATTRIBUTE_BS_RT},\r
+};\r
+GLOBAL_VARIABLE_ENTRY mGlobalVariableList2[] = {\r
+  {L"Boot####",                              VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {L"Driver####",                            VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+  {L"Key####",                               VARIABLE_ATTRIBUTE_NV_BS_RT},\r
+};\r
 \r
 /**\r
   Routine used to track statistical information about variable usage.\r
@@ -1473,7 +1518,7 @@ AutoUpdateLangVariable (
 \r
   SetLanguageCodes = FALSE;\r
 \r
-  if (StrCmp (VariableName, L"PlatformLangCodes") == 0) {\r
+  if (StrCmp (VariableName, EFI_PLATFORM_LANG_CODES_VARIABLE_NAME) == 0) {\r
     //\r
     // PlatformLangCodes is a volatile variable, so it can not be updated at runtime.\r
     //\r
@@ -1503,7 +1548,7 @@ AutoUpdateLangVariable (
     mVariableModuleGlobal->PlatformLang = AllocateRuntimePool (DataSize);\r
     ASSERT (mVariableModuleGlobal->PlatformLang != NULL);\r
 \r
-  } else if (StrCmp (VariableName, L"LangCodes") == 0) {\r
+  } else if (StrCmp (VariableName, EFI_LANG_CODES_VARIABLE_NAME) == 0) {\r
     //\r
     // LangCodes is a volatile variable, so it can not be updated at runtime.\r
     //\r
@@ -1531,21 +1576,21 @@ AutoUpdateLangVariable (
     // Update Lang if PlatformLang is already set\r
     // Update PlatformLang if Lang is already set\r
     //\r
-    Status = FindVariable (L"PlatformLang", &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
+    Status = FindVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
     if (!EFI_ERROR (Status)) {\r
       //\r
       // Update Lang\r
       //\r
-      VariableName = L"PlatformLang";\r
+      VariableName = EFI_PLATFORM_LANG_VARIABLE_NAME;\r
       Data         = GetVariableDataPtr (Variable.CurrPtr);\r
       DataSize     = Variable.CurrPtr->DataSize;\r
     } else {\r
-      Status = FindVariable (L"Lang", &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
+      Status = FindVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
       if (!EFI_ERROR (Status)) {\r
         //\r
         // Update PlatformLang\r
         //\r
-        VariableName = L"Lang";\r
+        VariableName = EFI_LANG_VARIABLE_NAME;\r
         Data         = GetVariableDataPtr (Variable.CurrPtr);\r
         DataSize     = Variable.CurrPtr->DataSize;\r
       } else {\r
@@ -1562,7 +1607,7 @@ AutoUpdateLangVariable (
   //\r
   Attributes = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;\r
 \r
-  if (StrCmp (VariableName, L"PlatformLang") == 0) {\r
+  if (StrCmp (VariableName, EFI_PLATFORM_LANG_VARIABLE_NAME) == 0) {\r
     //\r
     // Update Lang when PlatformLangCodes/LangCodes were set.\r
     //\r
@@ -1585,9 +1630,9 @@ AutoUpdateLangVariable (
         //\r
         // Successfully convert PlatformLang to Lang, and set the BestLang value into Lang variable simultaneously.\r
         //\r
-        FindVariable (L"Lang", &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
+        FindVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
 \r
-        Status = UpdateVariable (L"Lang", &gEfiGlobalVariableGuid, BestLang,\r
+        Status = UpdateVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestLang,\r
                                  ISO_639_2_ENTRY_SIZE + 1, Attributes, 0, 0, &Variable, NULL);\r
 \r
         DEBUG ((EFI_D_INFO, "Variable Driver Auto Update PlatformLang, PlatformLang:%a, Lang:%a\n", BestPlatformLang, BestLang));\r
@@ -1596,7 +1641,7 @@ AutoUpdateLangVariable (
       }\r
     }\r
 \r
-  } else if (StrCmp (VariableName, L"Lang") == 0) {\r
+  } else if (StrCmp (VariableName, EFI_LANG_VARIABLE_NAME) == 0) {\r
     //\r
     // Update PlatformLang when PlatformLangCodes/LangCodes were set.\r
     //\r
@@ -1619,9 +1664,9 @@ AutoUpdateLangVariable (
         //\r
         // Successfully convert Lang to PlatformLang, and set the BestPlatformLang value into PlatformLang variable simultaneously.\r
         //\r
-        FindVariable (L"PlatformLang", &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
+        FindVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
 \r
-        Status = UpdateVariable (L"PlatformLang", &gEfiGlobalVariableGuid, BestPlatformLang,\r
+        Status = UpdateVariable (EFI_PLATFORM_LANG_VARIABLE_NAME, &gEfiGlobalVariableGuid, BestPlatformLang,\r
                                  AsciiStrSize (BestPlatformLang), Attributes, 0, 0, &Variable, NULL);\r
 \r
         DEBUG ((EFI_D_INFO, "Variable Driver Auto Update Lang, Lang:%a, PlatformLang:%a\n", BestLang, BestPlatformLang));\r
@@ -2327,6 +2372,63 @@ IsHwErrRecVariable (
   return TRUE;\r
 }\r
 \r
+/**\r
+  This code checks if variable guid is global variable guid first.\r
+  If yes, further check if variable name is in mGlobalVariableList or mGlobalVariableList2 and attributes matched.\r
+\r
+  @param[in] VariableName       Pointer to variable name.\r
+  @param[in] VendorGuid         Variable Vendor Guid.\r
+  @param[in] Attributes         Attributes of the variable.\r
+\r
+  @retval EFI_SUCCESS           Variable is not global variable, or Variable is global variable, variable name is in the lists and attributes matched.\r
+  @retval EFI_INVALID_PARAMETER Variable is global variable, but variable name is not in the lists or attributes unmatched.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CheckEfiGlobalVariable (\r
+  IN CHAR16             *VariableName,\r
+  IN EFI_GUID           *VendorGuid,\r
+  IN UINT32             Attributes\r
+  )\r
+{\r
+  UINTN     Index;\r
+  UINTN     NameLength;\r
+\r
+  if (CompareGuid (VendorGuid, &gEfiGlobalVariableGuid)){\r
+    //\r
+    // Try list 1, exactly match.\r
+    //\r
+    for (Index = 0; Index < sizeof (mGlobalVariableList)/sizeof (mGlobalVariableList[0]); Index++) {\r
+      if ((StrCmp (mGlobalVariableList[Index].Name, VariableName) == 0) &&\r
+          (Attributes == 0 || (Attributes & (~EFI_VARIABLE_APPEND_WRITE)) == mGlobalVariableList[Index].Attributes)) {\r
+        return EFI_SUCCESS;\r
+      }\r
+    }\r
+\r
+    //\r
+    // Try list 2.\r
+    //\r
+    NameLength = StrLen (VariableName) - 4;\r
+    for (Index = 0; Index < sizeof (mGlobalVariableList2)/sizeof (mGlobalVariableList2[0]); Index++) {\r
+      if ((StrLen (VariableName) == StrLen (mGlobalVariableList2[Index].Name)) &&\r
+          (StrnCmp (mGlobalVariableList2[Index].Name, VariableName, NameLength) == 0) &&\r
+          IsHexaDecimalDigitCharacter (VariableName[NameLength]) &&\r
+          IsHexaDecimalDigitCharacter (VariableName[NameLength + 1]) &&\r
+          IsHexaDecimalDigitCharacter (VariableName[NameLength + 2]) &&\r
+          IsHexaDecimalDigitCharacter (VariableName[NameLength + 3]) &&\r
+          (Attributes == 0 || (Attributes & (~EFI_VARIABLE_APPEND_WRITE)) == mGlobalVariableList2[Index].Attributes)) {\r
+        return EFI_SUCCESS;\r
+      }\r
+    }\r
+\r
+    DEBUG ((EFI_D_INFO, "[Variable]: set global variable with invalid variable name or attributes - %g:%s:%x\n", VendorGuid, VariableName, Attributes));\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 /**\r
   Mark a variable that will become read-only after leaving the DXE phase of execution.\r
 \r
@@ -2787,6 +2889,11 @@ VariableServiceSetVariable (
     }\r
   }\r
 \r
+  Status = CheckEfiGlobalVariable (VariableName, VendorGuid, Attributes);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
   AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
 \r
   //\r
index ebd0b50b14053e08ea028cde32abc6ce9fa0fa81..9991dfe3218695dbcf92bb79697dab8fab63fd8c 100644 (file)
@@ -44,7 +44,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Guid/FaultTolerantWrite.h>\r
 #include <Guid/HardwareErrorVariable.h>\r
 \r
-#define VARIABLE_RECLAIM_THRESHOLD (1024)\r
 #define EFI_VARIABLE_ATTRIBUTES_MASK (EFI_VARIABLE_NON_VOLATILE | \\r
                                       EFI_VARIABLE_BOOTSERVICE_ACCESS | \\r
                                       EFI_VARIABLE_RUNTIME_ACCESS | \\r
@@ -53,6 +52,15 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
                                       EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \\r
                                       EFI_VARIABLE_APPEND_WRITE)\r
 \r
+#define VARIABLE_ATTRIBUTE_BS_RT        (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS)\r
+#define VARIABLE_ATTRIBUTE_NV_BS_RT     (VARIABLE_ATTRIBUTE_BS_RT | EFI_VARIABLE_NON_VOLATILE)\r
+#define VARIABLE_ATTRIBUTE_NV_BS_RT_AT  (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS)\r
+\r
+typedef struct {\r
+  CHAR16      *Name;\r
+  UINT32      Attributes;\r
+} GLOBAL_VARIABLE_ENTRY;\r
+\r
 ///\r
 /// The size of a 3 character ISO639 language code.\r
 ///\r