]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/VariableAuthenticated/Pei/Variable.c
Sync the fix for recovery mode from MdeModulePkg.
[mirror_edk2.git] / SecurityPkg / VariableAuthenticated / Pei / Variable.c
index 1fd051b3540e52ba6f008239075332c40ad343df..f637675157791838f2eec9bdeca44bf0c255b5aa 100644 (file)
@@ -32,6 +32,32 @@ EFI_PEI_PPI_DESCRIPTOR     mPpiListVariable = {
 };\r
 \r
 \r
+/**\r
+  Check if it runs in Recovery mode.\r
+  \r
+  @param  PeiServices  General purpose services available to every PEIM.\r
+\r
+  @retval TRUE         It's in Recovery mode.\r
+  @retval FALSE        It's not in Recovery mode.\r
+\r
+**/\r
+BOOLEAN\r
+IsInRecoveryMode (\r
+  IN CONST EFI_PEI_SERVICES          **PeiServices\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_BOOT_MODE           BootMode;\r
+\r
+  Status = (*PeiServices)->GetBootMode (PeiServices, &BootMode);\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  if (BootMode == BOOT_IN_RECOVERY_MODE) {\r
+    return TRUE;\r
+  }\r
+  return FALSE;\r
+}\r
+\r
 /**\r
   Provide the functionality of the variable services.\r
   \r
@@ -50,23 +76,7 @@ PeimInitializeVariableServices (
   IN CONST EFI_PEI_SERVICES          **PeiServices\r
   )\r
 {\r
-  EFI_BOOT_MODE BootMode;\r
-  EFI_STATUS    Status;\r
-\r
-  //\r
-  // Check if this is recovery boot path. If no, publish the variable access capability\r
-  // to other modules. If yes, the content of variable area is not reliable. Therefore,\r
-  // in this case we should not provide variable service to other pei modules. \r
-  // \r
-  Status = (*PeiServices)->GetBootMode (PeiServices, &BootMode);\r
-  ASSERT_EFI_ERROR (Status);\r
-  \r
-  if (BootMode == BOOT_IN_RECOVERY_MODE) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
   return PeiServicesInstallPpi (&mPpiListVariable);\r
-\r
 }\r
 \r
 /**\r
@@ -548,6 +558,16 @@ PeiGetVariable (
   if (VariableName == NULL || VariableGuid == NULL || DataSize == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
+\r
+  //\r
+  // Check if this is recovery boot path.\r
+  // If yes, the content of variable area is not reliable. Therefore we directly\r
+  // return EFI_NOT_FOUND. \r
+  // \r
+  if (IsInRecoveryMode(PeiServices)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
   //\r
   // Find existing variable\r
   //\r
@@ -626,6 +646,15 @@ PeiGetNextVariableName (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  //\r
+  // Check if this is recovery boot path.\r
+  // If yes, the content of variable area is not reliable. Therefore we directly\r
+  // return EFI_NOT_FOUND. \r
+  //   \r
+  if (IsInRecoveryMode(PeiServices)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
   Status = FindVariable (PeiServices, VariableName, VariableGuid, &Variable);\r
   if (Variable.CurrPtr == NULL || Status != EFI_SUCCESS) {\r
     return Status;\r