]> git.proxmox.com Git - mirror_edk2.git/commitdiff
SecurityPkg Variable: Support the new introduced PcdMaxAuthVariableSize.
authorStar Zeng <star.zeng@intel.com>
Wed, 10 Jun 2015 07:52:12 +0000 (07:52 +0000)
committerlzeng14 <lzeng14@Edk2>
Wed, 10 Jun 2015 07:52:12 +0000 (07:52 +0000)
1. If PcdMaxAuthVariableSize is set to 0, keep current behavior as is and
PcdMaxVariableSize used.
2. If PcdMaxAuthVariableSize is set to non 0, it will work on
authenticated variables.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17610 6f19259b-4bc3-4df7-8a09-765794883524

SecurityPkg/VariableAuthenticated/RuntimeDxe/AuthService.c
SecurityPkg/VariableAuthenticated/RuntimeDxe/AuthService.h
SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c
SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.h
SecurityPkg/VariableAuthenticated/RuntimeDxe/VariableRuntimeDxe.inf
SecurityPkg/VariableAuthenticated/RuntimeDxe/VariableSmm.c
SecurityPkg/VariableAuthenticated/RuntimeDxe/VariableSmm.inf
SecurityPkg/VariableAuthenticated/RuntimeDxe/VariableSmmRuntimeDxe.c
SecurityPkg/VariableAuthenticated/RuntimeDxe/VariableSmmRuntimeDxe.inf

index 36d447027d89c4d7fdd21ae20a444eba96e6ccc4..9599c8a6d8a0bee5d0cd765bbc7c99e683bd3ab2 100644 (file)
@@ -124,13 +124,18 @@ InCustomMode (
 /**\r
   Initializes for authenticated varibale service.\r
 \r
+  @param[in] MaxAuthVariableSize    Reflect the overhead associated with the saving\r
+                                    of a single EFI authenticated variable with the exception\r
+                                    of the overhead associated with the length\r
+                                    of the string name of the EFI variable.\r
+\r
   @retval EFI_SUCCESS           Function successfully executed.\r
   @retval EFI_OUT_OF_RESOURCES  Fail to allocate enough memory resources.\r
 \r
 **/\r
 EFI_STATUS\r
 AutenticatedVariableServiceInitialize (\r
-  VOID\r
+  IN UINTN      MaxAuthVariableSize\r
   )\r
 {\r
   EFI_STATUS              Status;\r
@@ -158,7 +163,7 @@ AutenticatedVariableServiceInitialize (
   //\r
   // Reserve runtime buffer for public key database. The size excludes variable header and name size.\r
   //\r
-  mMaxKeyDbSize = PcdGet32 (PcdMaxVariableSize) - sizeof (VARIABLE_HEADER) - sizeof (AUTHVAR_KEYDB_NAME);\r
+  mMaxKeyDbSize = (UINT32) (MaxAuthVariableSize - sizeof (AUTHVAR_KEYDB_NAME));\r
   mMaxKeyNumber = mMaxKeyDbSize / EFI_CERT_TYPE_RSA2048_SIZE;\r
   mPubKeyStore  = AllocateRuntimePool (mMaxKeyDbSize);\r
   if (mPubKeyStore == NULL) {\r
@@ -168,7 +173,7 @@ AutenticatedVariableServiceInitialize (
   //\r
   // Reserve runtime buffer for certificate database. The size excludes variable header and name size.\r
   //\r
-  mMaxCertDbSize = PcdGet32 (PcdMaxVariableSize) - sizeof (VARIABLE_HEADER) - sizeof (EFI_CERT_DB_NAME);\r
+  mMaxCertDbSize = (UINT32) (MaxAuthVariableSize - sizeof (EFI_CERT_DB_NAME));\r
   mCertDbStore   = AllocateRuntimePool (mMaxCertDbSize);\r
   if (mCertDbStore == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
index f28c82578e3d73aacd467e933de75aa1bdc62362..56def50d5287aaefb15f25b99cd329ea813b35a7 100644 (file)
@@ -139,13 +139,18 @@ UpdatePlatformMode (
 /**\r
   Initializes for authenticated varibale service.\r
 \r
+  @param[in] MaxAuthVariableSize    Reflect the overhead associated with the saving\r
+                                    of a single EFI authenticated variable with the exception\r
+                                    of the overhead associated with the length\r
+                                    of the string name of the EFI variable.\r
+\r
   @retval EFI_SUCCESS           Function successfully executed.\r
-  @retval EFI_OUT_OF_RESOURCES  Fail to allocate enough memory resource.\r
+  @retval EFI_OUT_OF_RESOURCES  Fail to allocate enough memory resources.\r
 \r
 **/\r
 EFI_STATUS\r
 AutenticatedVariableServiceInitialize (\r
-  VOID\r
+  IN UINTN      MaxAuthVariableSize\r
   );\r
 \r
 /**\r
index 7ecc29b94b5766323dd275a242fd174c8ec28a5e..15d053186cb0a85b15b8d6ec7acda001a99eccf2 100644 (file)
@@ -2153,7 +2153,7 @@ UpdateVariable (
       // Trying to update NV variable prior to the installation of EFI_VARIABLE_WRITE_ARCH_PROTOCOL\r
       //\r
       return EFI_NOT_AVAILABLE_YET;\r
-    } else if ((Attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) != 0) {\r
+    } else if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) != 0) {\r
       //\r
       // Trying to update volatile authenticated variable prior to the installation of EFI_VARIABLE_WRITE_ARCH_PROTOCOL\r
       // The authenticated variable perhaps is not initialized, just return here.\r
@@ -2190,7 +2190,7 @@ UpdateVariable (
   // as a temporary storage.\r
   //\r
   NextVariable = GetEndPointer ((VARIABLE_STORE_HEADER *) ((UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase));\r
-  ScratchSize = MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 (PcdMaxHardwareErrorVariableSize));\r
+  ScratchSize = mVariableModuleGlobal->ScratchBufferSize;\r
   SetMem (NextVariable, ScratchSize, 0xff);\r
   DataReady = FALSE;\r
 \r
@@ -2309,9 +2309,13 @@ UpdateVariable (
         CopyMem (BufferForMerge, (UINT8 *) ((UINTN) Variable->CurrPtr + DataOffset), Variable->CurrPtr->DataSize);\r
 \r
         //\r
-        // Set Max Common Variable Data Size as default MaxDataSize\r
+        // Set Max Common/Auth Variable Data Size as default MaxDataSize\r
         //\r
-        MaxDataSize = PcdGet32 (PcdMaxVariableSize) - DataOffset;\r
+        if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) != 0) {\r
+          MaxDataSize = mVariableModuleGlobal->MaxAuthVariableSize - DataOffset;\r
+        } else {\r
+          MaxDataSize = mVariableModuleGlobal->MaxVariableSize - DataOffset;\r
+        }\r
 \r
         if ((CompareGuid (VendorGuid, &gEfiImageSecurityDatabaseGuid) &&\r
             ((StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE) == 0) || (StrCmp (VariableName, EFI_IMAGE_SECURITY_DATABASE1) == 0) ||\r
@@ -2351,7 +2355,7 @@ UpdateVariable (
         } else {\r
           //\r
           // For other Variables, append the new data to the end of existing data.\r
-          // Max Harware error record variable data size is different from common variable\r
+          // Max Harware error record variable data size is different from common/auth variable\r
           //\r
           if ((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {\r
             MaxDataSize = PcdGet32 (PcdMaxHardwareErrorVariableSize) - DataOffset;\r
@@ -3237,7 +3241,7 @@ VariableServiceSetVariable (
   //\r
   //  The size of the VariableName, including the Unicode Null in bytes plus\r
   //  the DataSize is limited to maximum size of PcdGet32 (PcdMaxHardwareErrorVariableSize)\r
-  //  bytes for HwErrRec, and PcdGet32 (PcdMaxVariableSize) bytes for the others.\r
+  //  bytes for HwErrRec.\r
   //\r
   if ((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {\r
     if (StrSize (VariableName) + PayloadSize > PcdGet32 (PcdMaxHardwareErrorVariableSize) - sizeof (VARIABLE_HEADER)) {\r
@@ -3249,10 +3253,16 @@ VariableServiceSetVariable (
   } else {\r
     //\r
     //  The size of the VariableName, including the Unicode Null in bytes plus\r
-    //  the DataSize is limited to maximum size of PcdGet32 (PcdMaxVariableSize) bytes.\r
+    //  the DataSize is limited to maximum size of Max(Auth)VariableSize bytes.\r
     //\r
-    if (StrSize (VariableName) + PayloadSize > PcdGet32 (PcdMaxVariableSize) - sizeof (VARIABLE_HEADER)) {\r
-      return EFI_INVALID_PARAMETER;\r
+    if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) != 0) {\r
+      if (StrSize (VariableName) + PayloadSize > mVariableModuleGlobal->MaxAuthVariableSize - sizeof (VARIABLE_HEADER)) {\r
+        return EFI_INVALID_PARAMETER;\r
+      }\r
+    } else {\r
+      if (StrSize (VariableName) + PayloadSize > mVariableModuleGlobal->MaxVariableSize - sizeof (VARIABLE_HEADER)) {\r
+        return EFI_INVALID_PARAMETER;\r
+      }\r
     }\r
   }\r
 \r
@@ -3442,9 +3452,13 @@ VariableServiceQueryVariableInfoInternal (
     }\r
 \r
     //\r
-    // Let *MaximumVariableSize be PcdGet32 (PcdMaxVariableSize) with the exception of the variable header size.\r
+    // Let *MaximumVariableSize be Max(Auth)VariableSize with the exception of the variable header size.\r
     //\r
-    *MaximumVariableSize = PcdGet32 (PcdMaxVariableSize) - sizeof (VARIABLE_HEADER);\r
+    if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) != 0) {\r
+      *MaximumVariableSize = mVariableModuleGlobal->MaxAuthVariableSize - sizeof (VARIABLE_HEADER);\r
+    } else {\r
+      *MaximumVariableSize = mVariableModuleGlobal->MaxVariableSize - sizeof (VARIABLE_HEADER);\r
+    }\r
   }\r
 \r
   //\r
@@ -3636,11 +3650,13 @@ ReclaimForOS(
   }\r
 \r
   RemainingHwErrVariableSpace = PcdGet32 (PcdHwErrStorageSize) - mVariableModuleGlobal->HwErrVariableTotalSize;\r
+\r
   //\r
   // Check if the free area is below a threshold.\r
   //\r
-  if ((RemainingCommonRuntimeVariableSpace < PcdGet32 (PcdMaxVariableSize))\r
-    || ((PcdGet32 (PcdHwErrStorageSize) != 0) &&\r
+  if (((RemainingCommonRuntimeVariableSpace < mVariableModuleGlobal->MaxVariableSize) ||\r
+       (RemainingCommonRuntimeVariableSpace < mVariableModuleGlobal->MaxAuthVariableSize)) ||\r
+      ((PcdGet32 (PcdHwErrStorageSize) != 0) &&\r
        (RemainingHwErrVariableSpace < PcdGet32 (PcdMaxHardwareErrorVariableSize)))){\r
     Status = Reclaim (\r
             mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase,\r
@@ -3767,17 +3783,17 @@ InitNonVolatileVariableStore (
   // Note that in EdkII variable driver implementation, Hardware Error Record type variable\r
   // is stored with common variable in the same NV region. So the platform integrator should\r
   // ensure that the value of PcdHwErrStorageSize is less than the value of\r
-  // VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)).\r
+  // (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)).\r
   //\r
   ASSERT (HwErrStorageSize < (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)));\r
   //\r
   // Ensure that the value of PcdMaxUserNvVariableSpaceSize is less than the value of\r
-  // VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)) - PcdGet32 (PcdHwErrStorageSize).\r
+  // (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)) - PcdGet32 (PcdHwErrStorageSize).\r
   //\r
   ASSERT (MaxUserNvVariableSpaceSize < (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER) - HwErrStorageSize));\r
   //\r
   // Ensure that the value of PcdBoottimeReservedNvVariableSpaceSize is less than the value of\r
-  // VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)) - PcdGet32 (PcdHwErrStorageSize).\r
+  // (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)) - PcdGet32 (PcdHwErrStorageSize).\r
   //\r
   ASSERT (BoottimeReservedNvVariableSpaceSize < (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER) - HwErrStorageSize));\r
 \r
@@ -3788,9 +3804,12 @@ InitNonVolatileVariableStore (
   DEBUG ((EFI_D_INFO, "Variable driver common space: 0x%x 0x%x 0x%x\n", mVariableModuleGlobal->CommonVariableSpace, mVariableModuleGlobal->CommonMaxUserVariableSpace, mVariableModuleGlobal->CommonRuntimeVariableSpace));\r
 \r
   //\r
-  // The max variable or hardware error variable size should be < variable store size.\r
+  // The max NV variable size should be < (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)).\r
   //\r
-  ASSERT(MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 (PcdMaxHardwareErrorVariableSize)) < VariableStoreLength);\r
+  ASSERT (MAX_NV_VARIABLE_SIZE < (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)));\r
+\r
+  mVariableModuleGlobal->MaxVariableSize = PcdGet32 (PcdMaxVariableSize);\r
+  mVariableModuleGlobal->MaxAuthVariableSize = ((PcdGet32 (PcdMaxAuthVariableSize) != 0) ? PcdGet32 (PcdMaxAuthVariableSize) : mVariableModuleGlobal->MaxVariableSize);\r
 \r
   //\r
   // Parse non-volatile variable data and get last variable offset.\r
@@ -3963,7 +3982,7 @@ VariableWriteServiceInitialize (
   //\r
   // Authenticated variable initialize.\r
   //\r
-  Status = AutenticatedVariableServiceInitialize ();\r
+  Status = AutenticatedVariableServiceInitialize (mVariableModuleGlobal->MaxAuthVariableSize - sizeof (VARIABLE_HEADER));\r
 \r
   return Status;\r
 }\r
@@ -4019,7 +4038,8 @@ VariableCommonInitialize (
   //\r
   // Allocate memory for volatile variable store, note that there is a scratch space to store scratch data.\r
   //\r
-  ScratchSize = MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 (PcdMaxHardwareErrorVariableSize));\r
+  ScratchSize = MAX_NV_VARIABLE_SIZE;\r
+  mVariableModuleGlobal->ScratchBufferSize = ScratchSize;\r
   VolatileVariableStore = AllocateRuntimePool (PcdGet32 (PcdVariableStoreSize) + ScratchSize);\r
   if (VolatileVariableStore == NULL) {\r
     if (mVariableModuleGlobal->VariableGlobal.HobVariableBase != 0) {\r
index fd4dab2429ab0c9af046f3b19177a97326efff0d..4a4595fe4cb3c700eb0b6ac16cb38e3f89d2807f 100644 (file)
@@ -61,6 +61,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define VARIABLE_ATTRIBUTE_NV_BS_RT_HR  (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_HARDWARE_ERROR_RECORD)\r
 #define VARIABLE_ATTRIBUTE_NV_BS_RT_AW  (VARIABLE_ATTRIBUTE_NV_BS_RT | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS)\r
 #define VARIABLE_ATTRIBUTE_NV_BS_RT_AT_HR_AW  (VARIABLE_ATTRIBUTE_NV_BS_RT_AT | EFI_VARIABLE_HARDWARE_ERROR_RECORD | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS)\r
+#define VARIABLE_ATTRIBUTE_AT_AW        (EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS)\r
+\r
+#define MAX_NV_VARIABLE_SIZE (MAX (MAX (PcdGet32 (PcdMaxVariableSize), \\r
+                                        PcdGet32 (PcdMaxAuthVariableSize)), \\r
+                                   PcdGet32 (PcdMaxHardwareErrorVariableSize)))\r
 \r
 ///\r
 /// The size of a 3 character ISO639 language code.\r
@@ -106,6 +111,9 @@ typedef struct {
   UINTN           CommonVariableTotalSize;\r
   UINTN           CommonUserVariableTotalSize;\r
   UINTN           HwErrVariableTotalSize;\r
+  UINTN           MaxVariableSize;\r
+  UINTN           MaxAuthVariableSize;\r
+  UINTN           ScratchBufferSize;\r
   CHAR8           *PlatformLangCodes;\r
   CHAR8           *LangCodes;\r
   CHAR8           *PlatformLang;\r
index cbf7da0add6d765c8b62770757fe657794f25164..2b1b1c0b58126a9f5e3d8610d77853830523c90f 100644 (file)
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase       ## SOMETIMES_CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64     ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize                  ## CONSUMES\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize              ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize     ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize                ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize                 ## CONSUMES\r
index a1ac461542064f2266460b6078a14c4ff48113ce..1eb169ac6e23de393034bde71ba0f0a3194267ad 100644 (file)
@@ -932,7 +932,7 @@ VariableServiceInitialize (
                     );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  mVariableBufferPayloadSize = MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 (PcdMaxHardwareErrorVariableSize)) +\r
+  mVariableBufferPayloadSize = MAX_NV_VARIABLE_SIZE +\r
                                OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) - sizeof (VARIABLE_HEADER);\r
 \r
   Status = gSmst->SmmAllocatePool (\r
index efb80f366505192bce3328b4a8babb4cf086a716..00181dbea8c67c67792c91f73a9fa97b2437a434 100644 (file)
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase       ## SOMETIMES_CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64     ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize                  ## CONSUMES\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize              ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize     ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize                ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize                 ## CONSUMES\r
   TRUE\r
   \r
 [UserExtensions.TianoCore."ExtraFiles"]\r
-  VariableSmmExtra.uni
\ No newline at end of file
+  VariableSmmExtra.uni\r
index e87e12fc994e09088fe4e1ca9db088baff6e7586..94b60bf5cf25456de5a1765a6f764e3530cac446 100644 (file)
@@ -59,6 +59,10 @@ EFI_LOCK                         mVariableServicesLock;
 EDKII_VARIABLE_LOCK_PROTOCOL     mVariableLock;\r
 EDKII_VAR_CHECK_PROTOCOL         mVarCheck;\r
 \r
+#define MAX_NV_VARIABLE_SIZE (MAX (MAX (PcdGet32 (PcdMaxVariableSize), \\r
+                                        PcdGet32 (PcdMaxAuthVariableSize)), \\r
+                                   PcdGet32 (PcdMaxHardwareErrorVariableSize)))\r
+\r
 /**\r
   SecureBoot Hook for SetVariable.\r
 \r
@@ -931,7 +935,7 @@ SmmVariableReady (
   //\r
   // Allocate memory for variable communicate buffer.\r
   //\r
-  mVariableBufferPayloadSize = MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 (PcdMaxHardwareErrorVariableSize)) +\r
+  mVariableBufferPayloadSize = MAX_NV_VARIABLE_SIZE +\r
                                OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) - sizeof (VARIABLE_HEADER);\r
   mVariableBufferSize  = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + mVariableBufferPayloadSize;\r
   mVariableBuffer      = AllocateRuntimePool (mVariableBufferSize);\r
index e48a0f16f69b9091a23f822c038340a15fa43c95..db6a4de6abf8a0e9990eb0e8ed1b76f44b2bc284 100644 (file)
@@ -92,6 +92,7 @@
 \r
 [Pcd]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize                 ## CONSUMES\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize             ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize    ## CONSUMES\r
 \r
 [Depex]\r