]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/VariableAuthenticated/RuntimeDxe/AuthService.c
1. Remove “Force clear PK” feature in AuthVarialbe driver.
[mirror_edk2.git] / SecurityPkg / VariableAuthenticated / RuntimeDxe / AuthService.c
index f7a9888ce1be840643f85b70e90cfd269185132b..4036885570a04c737fca4273ceb109c3361f10c7 100644 (file)
@@ -2,7 +2,7 @@
   Implement authentication services for the authenticated variable\r
   service in UEFI2.2.\r
 \r
-Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2012, 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
@@ -65,6 +65,53 @@ EFI_SIGNATURE_ITEM mSupportSigItem[] = {
   {EFI_CERT_SHA512_GUID,          0,               64           }\r
 };\r
 \r
+/**\r
+  Determine whether this operation needs a physical present user.\r
+\r
+  @param[in]      VariableName            Name of the Variable.\r
+  @param[in]      VendorGuid              GUID of the Variable.\r
+\r
+  @retval TRUE      This variable is protected, only a physical present user could set this variable.\r
+  @retval FALSE     This variable is not protected.\r
+  \r
+**/\r
+BOOLEAN\r
+NeedPhysicallyPresent(\r
+  IN     CHAR16         *VariableName,\r
+  IN     EFI_GUID       *VendorGuid\r
+  )\r
+{\r
+  if ((CompareGuid (VendorGuid, &gEfiSecureBootEnableDisableGuid) && (StrCmp (VariableName, EFI_SECURE_BOOT_ENABLE_NAME) == 0))\r
+    || (CompareGuid (VendorGuid, &gEfiCustomModeEnableGuid) && (StrCmp (VariableName, EFI_CUSTOM_MODE_NAME) == 0))) {\r
+    return TRUE;\r
+  }\r
+  \r
+  return FALSE;\r
+}\r
+\r
+/**\r
+  Determine whether the platform is operating in Custom Secure Boot mode.\r
+\r
+  @retval TRUE           The platform is operating in Custom mode.\r
+  @retval FALSE          The platform is operating in Standard mode.\r
+\r
+**/\r
+BOOLEAN\r
+InCustomMode (\r
+  VOID\r
+  )\r
+{\r
+  VARIABLE_POINTER_TRACK  Variable;\r
+\r
+  FindVariable (EFI_CUSTOM_MODE_NAME, &gEfiCustomModeEnableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
+  if (Variable.CurrPtr != NULL && *(GetVariableDataPtr (Variable.CurrPtr)) == CUSTOM_SECURE_BOOT_MODE) {\r
+    return TRUE;\r
+  }\r
+  \r
+  return FALSE;\r
+}\r
+\r
+\r
 /**\r
   Internal function to delete a Variable given its name and GUID, no authentication\r
   required.\r
@@ -85,7 +132,7 @@ DeleteVariable (
   EFI_STATUS              Status;\r
   VARIABLE_POINTER_TRACK  Variable;\r
 \r
-  Status = FindVariable (VariableName, VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal);\r
+  Status = FindVariable (VariableName, VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
   if (EFI_ERROR (Status)) {\r
     return EFI_SUCCESS;\r
   }\r
@@ -116,6 +163,7 @@ AutenticatedVariableServiceInitialize (
   UINTN                   CtxSize;\r
   UINT8                   SecureBootMode;\r
   UINT8                   SecureBootEnable;\r
+  UINT8                   CustomMode;\r
 \r
   //\r
   // Initialize hash context.\r
@@ -151,7 +199,8 @@ AutenticatedVariableServiceInitialize (
              AUTHVAR_KEYDB_NAME,\r
              &gEfiAuthenticatedVariableGuid,\r
              &Variable,\r
-             &mVariableModuleGlobal->VariableGlobal\r
+             &mVariableModuleGlobal->VariableGlobal,\r
+             FALSE\r
              );\r
 \r
   if (Variable.CurrPtr == NULL) {\r
@@ -183,7 +232,7 @@ AutenticatedVariableServiceInitialize (
     mPubKeyNumber = (UINT32) (DataSize / EFI_CERT_TYPE_RSA2048_SIZE);\r
   }\r
 \r
-  FindVariable (EFI_PLATFORM_KEY_NAME, &gEfiGlobalVariableGuid, &PkVariable, &mVariableModuleGlobal->VariableGlobal);\r
+  FindVariable (EFI_PLATFORM_KEY_NAME, &gEfiGlobalVariableGuid, &PkVariable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
   if (PkVariable.CurrPtr == NULL) {\r
     DEBUG ((EFI_D_INFO, "Variable %s does not exist.\n", EFI_PLATFORM_KEY_NAME));\r
   } else {\r
@@ -199,7 +248,8 @@ AutenticatedVariableServiceInitialize (
              EFI_SETUP_MODE_NAME,\r
              &gEfiGlobalVariableGuid,\r
              &Variable,\r
-             &mVariableModuleGlobal->VariableGlobal\r
+             &mVariableModuleGlobal->VariableGlobal,\r
+             FALSE\r
              );\r
 \r
   if (Variable.CurrPtr == NULL) {\r
@@ -235,7 +285,8 @@ AutenticatedVariableServiceInitialize (
              EFI_SIGNATURE_SUPPORT_NAME,\r
              &gEfiGlobalVariableGuid,\r
              &Variable,\r
-             &mVariableModuleGlobal->VariableGlobal\r
+             &mVariableModuleGlobal->VariableGlobal,\r
+             FALSE\r
              );\r
 \r
   if (Variable.CurrPtr == NULL) {\r
@@ -259,7 +310,7 @@ AutenticatedVariableServiceInitialize (
   // If "SecureBootEnable" variable is SECURE_BOOT_DISABLE, Set "SecureBoot" variable to SECURE_BOOT_MODE_DISABLE.\r
   //\r
   SecureBootEnable = SECURE_BOOT_MODE_DISABLE;\r
-  FindVariable (EFI_SECURE_BOOT_ENABLE_NAME, &gEfiSecureBootEnableDisableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal);\r
+  FindVariable (EFI_SECURE_BOOT_ENABLE_NAME, &gEfiSecureBootEnableDisableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
   if (Variable.CurrPtr != NULL) {\r
     SecureBootEnable = *(GetVariableDataPtr (Variable.CurrPtr));\r
   } else if (mPlatformMode == USER_MODE) {\r
@@ -288,7 +339,7 @@ AutenticatedVariableServiceInitialize (
   } else {\r
     SecureBootMode = SECURE_BOOT_MODE_DISABLE;\r
   }\r
-  FindVariable (EFI_SECURE_BOOT_MODE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal);\r
+  FindVariable (EFI_SECURE_BOOT_MODE_NAME, &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
   Status = UpdateVariable (\r
              EFI_SECURE_BOOT_MODE_NAME,\r
              &gEfiGlobalVariableGuid,\r
@@ -309,33 +360,33 @@ AutenticatedVariableServiceInitialize (
   DEBUG ((EFI_D_INFO, "Variable %s is %x\n", EFI_SECURE_BOOT_ENABLE_NAME, SecureBootEnable));\r
 \r
   //\r
-  // Detect whether a secure platform-specific method to clear PK(Platform Key)\r
-  // is configured by platform owner. This method is provided for users force to clear PK\r
-  // in case incorrect enrollment mis-haps.\r
+  // Check "CustomMode" variable's existence.\r
   //\r
-  if (ForceClearPK ()) {\r
-    DEBUG ((EFI_D_INFO, "Variable PK/KEK/DB/DBX will be cleared in clear PK mode.\n"));\r
-\r
+  FindVariable (EFI_CUSTOM_MODE_NAME, &gEfiCustomModeEnableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
+  if (Variable.CurrPtr != NULL) {\r
+    CustomMode = *(GetVariableDataPtr (Variable.CurrPtr));\r
+  } else {\r
     //\r
-    // 1. Clear PK.\r
+    // "CustomMode" not exist, initialize it in STANDARD_SECURE_BOOT_MODE.\r
     //\r
-    Status = DeleteVariable (EFI_PLATFORM_KEY_NAME, &gEfiGlobalVariableGuid);\r
+    CustomMode = STANDARD_SECURE_BOOT_MODE;\r
+    Status = UpdateVariable (\r
+               EFI_CUSTOM_MODE_NAME,\r
+               &gEfiCustomModeEnableGuid,\r
+               &CustomMode,\r
+               sizeof (UINT8),\r
+               EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+               0,\r
+               0,\r
+               &Variable,\r
+               NULL\r
+               );\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
-\r
-    //\r
-    // 2. Update "SetupMode" variable to SETUP_MODE.\r
-    //\r
-    UpdatePlatformMode (SETUP_MODE);\r
-\r
-    //\r
-    // 3. Clear KEK, DB and DBX.\r
-    //\r
-    DeleteVariable (EFI_KEY_EXCHANGE_KEY_NAME, &gEfiGlobalVariableGuid);\r
-    DeleteVariable (EFI_IMAGE_SECURITY_DATABASE, &gEfiImageSecurityDatabaseGuid);\r
-    DeleteVariable (EFI_IMAGE_SECURITY_DATABASE1, &gEfiImageSecurityDatabaseGuid);\r
   }\r
+  \r
+  DEBUG ((EFI_D_INFO, "Variable %s is %x\n", EFI_CUSTOM_MODE_NAME, CustomMode));\r
 \r
   return Status;\r
 }\r
@@ -367,7 +418,8 @@ AddPubKeyInStore (
              AUTHVAR_KEYDB_NAME,\r
              &gEfiAuthenticatedVariableGuid,\r
              &Variable,\r
-             &mVariableModuleGlobal->VariableGlobal\r
+             &mVariableModuleGlobal->VariableGlobal,\r
+             FALSE\r
              );\r
   ASSERT_EFI_ERROR (Status);\r
   //\r
@@ -551,7 +603,8 @@ UpdatePlatformMode (
              EFI_SETUP_MODE_NAME,\r
              &gEfiGlobalVariableGuid,\r
              &Variable,\r
-             &mVariableModuleGlobal->VariableGlobal\r
+             &mVariableModuleGlobal->VariableGlobal,\r
+             FALSE\r
              );\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
@@ -592,7 +645,8 @@ UpdatePlatformMode (
              EFI_SECURE_BOOT_MODE_NAME,\r
              &gEfiGlobalVariableGuid,\r
              &Variable,\r
-             &mVariableModuleGlobal->VariableGlobal\r
+             &mVariableModuleGlobal->VariableGlobal,\r
+             FALSE\r
              );\r
   //\r
   // If "SecureBoot" variable exists, then check "SetupMode" variable update.\r
@@ -634,7 +688,8 @@ UpdatePlatformMode (
              EFI_SECURE_BOOT_ENABLE_NAME,\r
              &gEfiSecureBootEnableDisableGuid,\r
              &Variable,\r
-             &mVariableModuleGlobal->VariableGlobal\r
+             &mVariableModuleGlobal->VariableGlobal,\r
+             FALSE\r
              );\r
 \r
   if (SecureBootMode == SECURE_BOOT_MODE_ENABLE) {\r
@@ -811,7 +866,7 @@ ProcessVarWithPk (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (mPlatformMode == USER_MODE) {\r
+  if (mPlatformMode == USER_MODE && !(InCustomMode() && UserPhysicalPresent())) {\r
 \r
     if ((Attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) != 0) {\r
       //\r
@@ -860,7 +915,8 @@ ProcessVarWithPk (
                  EFI_PLATFORM_KEY_NAME,\r
                  &gEfiGlobalVariableGuid,\r
                  &PkVariable,\r
-                 &mVariableModuleGlobal->VariableGlobal\r
+                 &mVariableModuleGlobal->VariableGlobal,\r
+                 FALSE\r
                  );\r
       ASSERT_EFI_ERROR (Status);\r
 \r
@@ -901,7 +957,7 @@ ProcessVarWithPk (
     }\r
   } else {\r
     //\r
-    // Process PK or KEK in Setup mode.\r
+    // Process PK or KEK in Setup mode or Custom Secure Boot mode.\r
     //\r
     if ((Attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) != 0) {\r
       //\r
@@ -945,12 +1001,20 @@ ProcessVarWithPk (
                Variable,\r
                TimeStamp\r
                );\r
-    //\r
-    // If enroll PK in setup mode, need change to user mode.\r
-    //\r
-    if ((DataSize != 0) && IsPk) {\r
-      Status = UpdatePlatformMode (USER_MODE);\r
-    }\r
+\r
+    if (IsPk) {\r
+      if (PayloadSize != 0) {\r
+        //\r
+        // If enroll PK in setup mode, need change to user mode.\r
+        //\r
+        Status = UpdatePlatformMode (USER_MODE);\r
+      } else {\r
+        //\r
+        // If delete PK in custom mode, need change to setup mode.\r
+        //\r
+        UpdatePlatformMode (SETUP_MODE);\r
+      }\r
+    }   \r
   }\r
 \r
   return Status;\r
@@ -996,85 +1060,116 @@ ProcessVarWithKek (
   UINT8                           *Payload;\r
   UINTN                           PayloadSize;\r
   UINT64                          MonotonicCount;\r
+  EFI_TIME                        *TimeStamp;\r
+\r
+  if ((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) {\r
+    //\r
+    // DB and DBX should set EFI_VARIABLE_NON_VOLATILE attribute.\r
+    //\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
 \r
-  if (mPlatformMode == USER_MODE) {\r
-    if ((Attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) == 0) {\r
+  Status = EFI_SUCCESS;\r
+  if (mPlatformMode == USER_MODE && !(InCustomMode() && UserPhysicalPresent())) {\r
+    if (((Attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) == 0) &&\r
+        ((Attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) == 0)){\r
       //\r
-      // In user mode, should set EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS attribute.\r
+      // In user mode, should set EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS or\r
+      // EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute.\r
       //\r
       return EFI_INVALID_PARAMETER;\r
     }\r
 \r
-    CertData  = (EFI_VARIABLE_AUTHENTICATION *) Data;\r
-    CertBlock = (EFI_CERT_BLOCK_RSA_2048_SHA256 *) (CertData->AuthInfo.CertData);\r
-    if ((Variable->CurrPtr != NULL) && (CertData->MonotonicCount <= Variable->CurrPtr->MonotonicCount)) {\r
+    if ((Attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) != 0) {\r
       //\r
-      // Monotonic count check fail, suspicious replay attack, return EFI_SECURITY_VIOLATION.\r
+      // Time-based, verify against X509 Cert KEK.\r
       //\r
-      return EFI_SECURITY_VIOLATION;\r
-    }\r
-    //\r
-    // Get KEK database from variable.\r
-    //\r
-    Status = FindVariable (\r
-               EFI_KEY_EXCHANGE_KEY_NAME,\r
-               &gEfiGlobalVariableGuid,\r
-               &KekVariable,\r
-               &mVariableModuleGlobal->VariableGlobal\r
-               );\r
-    ASSERT_EFI_ERROR (Status);\r
+      return VerifyTimeBasedPayload (VariableName, VendorGuid, Data, DataSize, Variable, Attributes, FALSE, NULL);\r
+    } else if ((Attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) != 0) {\r
+      //\r
+      // Counter-based, verify against RSA2048 Cert KEK.\r
+      //\r
+      CertData  = (EFI_VARIABLE_AUTHENTICATION *) Data;\r
+      CertBlock = (EFI_CERT_BLOCK_RSA_2048_SHA256 *) (CertData->AuthInfo.CertData);\r
+      if ((Variable->CurrPtr != NULL) && (CertData->MonotonicCount <= Variable->CurrPtr->MonotonicCount)) {\r
+        //\r
+        // Monotonic count check fail, suspicious replay attack, return EFI_SECURITY_VIOLATION.\r
+        //\r
+        return EFI_SECURITY_VIOLATION;\r
+      }\r
+      //\r
+      // Get KEK database from variable.\r
+      //\r
+      Status = FindVariable (\r
+                 EFI_KEY_EXCHANGE_KEY_NAME,\r
+                 &gEfiGlobalVariableGuid,\r
+                 &KekVariable,\r
+                 &mVariableModuleGlobal->VariableGlobal,\r
+                 FALSE\r
+                 );\r
+      ASSERT_EFI_ERROR (Status);\r
 \r
-    KekDataSize = KekVariable.CurrPtr->DataSize;\r
-    KekList     = (EFI_SIGNATURE_LIST *) GetVariableDataPtr (KekVariable.CurrPtr);\r
+      KekDataSize = KekVariable.CurrPtr->DataSize;\r
+      KekList     = (EFI_SIGNATURE_LIST *) GetVariableDataPtr (KekVariable.CurrPtr);\r
 \r
-    //\r
-    // Enumerate all Kek items in this list to verify the variable certificate data.\r
-    // If anyone is authenticated successfully, it means the variable is correct!\r
-    //\r
-    IsFound   = FALSE;\r
-    while ((KekDataSize > 0) && (KekDataSize >= KekList->SignatureListSize)) {\r
-      if (CompareGuid (&KekList->SignatureType, &gEfiCertRsa2048Guid)) {\r
-        KekItem   = (EFI_SIGNATURE_DATA *) ((UINT8 *) KekList + sizeof (EFI_SIGNATURE_LIST) + KekList->SignatureHeaderSize);\r
-        KekCount  = (KekList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - KekList->SignatureHeaderSize) / KekList->SignatureSize;\r
-        for (Index = 0; Index < KekCount; Index++) {\r
-          if (CompareMem (KekItem->SignatureData, CertBlock->PublicKey, EFI_CERT_TYPE_RSA2048_SIZE) == 0) {\r
-            IsFound = TRUE;\r
-            break;\r
+      //\r
+      // Enumerate all Kek items in this list to verify the variable certificate data.\r
+      // If anyone is authenticated successfully, it means the variable is correct!\r
+      //\r
+      IsFound   = FALSE;\r
+      while ((KekDataSize > 0) && (KekDataSize >= KekList->SignatureListSize)) {\r
+        if (CompareGuid (&KekList->SignatureType, &gEfiCertRsa2048Guid)) {\r
+          KekItem   = (EFI_SIGNATURE_DATA *) ((UINT8 *) KekList + sizeof (EFI_SIGNATURE_LIST) + KekList->SignatureHeaderSize);\r
+          KekCount  = (KekList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - KekList->SignatureHeaderSize) / KekList->SignatureSize;\r
+          for (Index = 0; Index < KekCount; Index++) {\r
+            if (CompareMem (KekItem->SignatureData, CertBlock->PublicKey, EFI_CERT_TYPE_RSA2048_SIZE) == 0) {\r
+              IsFound = TRUE;\r
+              break;\r
+            }\r
+            KekItem = (EFI_SIGNATURE_DATA *) ((UINT8 *) KekItem + KekList->SignatureSize);\r
           }\r
-          KekItem = (EFI_SIGNATURE_DATA *) ((UINT8 *) KekItem + KekList->SignatureSize);\r
         }\r
+        KekDataSize -= KekList->SignatureListSize;\r
+        KekList = (EFI_SIGNATURE_LIST *) ((UINT8 *) KekList + KekList->SignatureListSize);\r
       }\r
-      KekDataSize -= KekList->SignatureListSize;\r
-      KekList = (EFI_SIGNATURE_LIST *) ((UINT8 *) KekList + KekList->SignatureListSize);\r
-    }\r
 \r
-    if (!IsFound) {\r
-      return EFI_SECURITY_VIOLATION;\r
-    }\r
+      if (!IsFound) {\r
+        return EFI_SECURITY_VIOLATION;\r
+      }\r
 \r
-    Status = VerifyCounterBasedPayload (Data, DataSize, CertBlock->PublicKey);\r
-    if (!EFI_ERROR (Status)) {\r
-      Status = UpdateVariable (\r
-                 VariableName,\r
-                 VendorGuid,\r
-                 (UINT8*)Data + AUTHINFO_SIZE,\r
-                 DataSize - AUTHINFO_SIZE,\r
-                 Attributes,\r
-                 0,\r
-                 CertData->MonotonicCount,\r
-                 Variable,\r
-                 NULL\r
-                 );\r
+      Status = VerifyCounterBasedPayload (Data, DataSize, CertBlock->PublicKey);\r
+      if (!EFI_ERROR (Status)) {\r
+        Status = UpdateVariable (\r
+                   VariableName,\r
+                   VendorGuid,\r
+                   (UINT8*)Data + AUTHINFO_SIZE,\r
+                   DataSize - AUTHINFO_SIZE,\r
+                   Attributes,\r
+                   0,\r
+                   CertData->MonotonicCount,\r
+                   Variable,\r
+                   NULL\r
+                   );\r
+      }\r
     }\r
   } else {\r
     //\r
-    // If in setup mode, no authentication needed.\r
+    // If in setup mode or custom secure boot mode, no authentication needed.\r
     //\r
-    if ((Attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) != 0) {\r
+    if ((Attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) != 0) {\r
+      //\r
+      // Time-based Authentication descriptor.\r
+      //\r
+      MonotonicCount = 0;\r
+      TimeStamp = &((EFI_VARIABLE_AUTHENTICATION_2 *) Data)->TimeStamp;\r
+      Payload = (UINT8 *) Data + AUTHINFO2_SIZE (Data);\r
+      PayloadSize = DataSize - AUTHINFO2_SIZE (Data);\r
+    } else if ((Attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) != 0) {\r
       //\r
       // Counter-based Authentication descriptor.\r
       //\r
       MonotonicCount = ((EFI_VARIABLE_AUTHENTICATION *) Data)->MonotonicCount;\r
+      TimeStamp = NULL;\r
       Payload = (UINT8*) Data + AUTHINFO_SIZE;\r
       PayloadSize = DataSize - AUTHINFO_SIZE;\r
     } else {\r
@@ -1082,6 +1177,7 @@ ProcessVarWithKek (
       // No Authentication descriptor.\r
       //\r
       MonotonicCount = 0;\r
+      TimeStamp = NULL;\r
       Payload = Data;\r
       PayloadSize = DataSize;\r
     }\r
@@ -1095,7 +1191,7 @@ ProcessVarWithKek (
                0,\r
                MonotonicCount,\r
                Variable,\r
-               NULL\r
+               TimeStamp\r
                );\r
   }\r
 \r
@@ -1148,6 +1244,13 @@ ProcessVariable (
   PubKey      = NULL;\r
   IsDeletion  = FALSE;\r
 \r
+  if (NeedPhysicallyPresent(VariableName, VendorGuid) && !UserPhysicalPresent()) {\r
+    //\r
+    // This variable is protected, only physical present user could modify its value.\r
+    //\r
+    return EFI_SECURITY_VIOLATION;\r
+  }\r
+  \r
   //\r
   // Process Time-based Authenticated variable.\r
   //\r
@@ -1538,7 +1641,8 @@ VerifyTimeBasedPayload (
                EFI_PLATFORM_KEY_NAME,\r
                &gEfiGlobalVariableGuid,\r
                &PkVariable,\r
-               &mVariableModuleGlobal->VariableGlobal\r
+               &mVariableModuleGlobal->VariableGlobal,\r
+               FALSE\r
                );\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
@@ -1571,7 +1675,8 @@ VerifyTimeBasedPayload (
                EFI_KEY_EXCHANGE_KEY_NAME,\r
                &gEfiGlobalVariableGuid,\r
                &KekVariable,\r
-               &mVariableModuleGlobal->VariableGlobal\r
+               &mVariableModuleGlobal->VariableGlobal,\r
+               FALSE\r
                );\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r