]> git.proxmox.com Git - mirror_edk2.git/commitdiff
If setting variable in Runtime and there has been a same GUID and name variable exist...
authorlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 30 Mar 2012 07:19:44 +0000 (07:19 +0000)
committerlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 30 Mar 2012 07:19:44 +0000 (07:19 +0000)
Signed-off-by: lzeng14
Reviewed-by: tye
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13156 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c
SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.h

index 5aa6e3273d5b0a7e6032eb3cd46a2460e8708b42..94ec660c04b657522b8a31dc3190e26de485ff8e 100644 (file)
@@ -3,7 +3,7 @@
   The common variable operation routines shared by DXE_RINTIME variable \r
   module and DXE_SMM variable module.\r
   \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 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
@@ -718,6 +718,8 @@ Reclaim (
 \r
   @param  VariableName        Name of the variable to be found\r
   @param  VendorGuid          Vendor GUID to be found.\r
+  @param  IgnoreRtCheck       Ignore EFI_VARIABLE_RUNTIME_ACCESS attribute\r
+                              check at runtime when searching variable.\r
   @param  PtrTrack            Variable Track Pointer structure that contains Variable Information.\r
 \r
   @retval  EFI_SUCCESS            Variable found successfully\r
@@ -727,6 +729,7 @@ EFI_STATUS
 FindVariableEx (\r
   IN     CHAR16                  *VariableName,\r
   IN     EFI_GUID                *VendorGuid,\r
+  IN     BOOLEAN                 IgnoreRtCheck,\r
   IN OUT VARIABLE_POINTER_TRACK  *PtrTrack\r
   )\r
 {\r
@@ -745,7 +748,7 @@ FindVariableEx (
     if (PtrTrack->CurrPtr->State == VAR_ADDED || \r
         PtrTrack->CurrPtr->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)\r
        ) {\r
-      if (!AtRuntime () || ((PtrTrack->CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) != 0)) {\r
+      if (IgnoreRtCheck || !AtRuntime () || ((PtrTrack->CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) != 0)) {\r
         if (VariableName[0] == 0) {\r
           if (PtrTrack->CurrPtr->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {\r
             InDeletedVariable   = PtrTrack->CurrPtr;\r
@@ -781,7 +784,9 @@ FindVariableEx (
   This code finds variable in storage blocks of volatile and non-volatile storage areas.\r
   If VariableName is an empty string, then we just return the first\r
   qualified variable without comparing VariableName and VendorGuid.\r
-  Otherwise, VariableName and VendorGuid are compared.\r
+  If IgnoreRtCheck is TRUE, then we ignore the EFI_VARIABLE_RUNTIME_ACCESS attribute check\r
+  at runtime when searching existing variable, only VariableName and VendorGuid are compared.\r
+  Otherwise, variables without EFI_VARIABLE_RUNTIME_ACCESS are not visible at runtime.\r
 \r
   @param  VariableName                Name of the variable to be found.\r
   @param  VendorGuid                  Vendor GUID to be found.\r
@@ -790,6 +795,8 @@ FindVariableEx (
   @param  Global                      Pointer to VARIABLE_GLOBAL structure, including\r
                                       base of volatile variable storage area, base of\r
                                       NV variable storage area, and a lock.\r
+  @param  IgnoreRtCheck               Ignore EFI_VARIABLE_RUNTIME_ACCESS attribute\r
+                                      check at runtime when searching variable.\r
 \r
   @retval EFI_INVALID_PARAMETER       If VariableName is not an empty string, while\r
                                       VendorGuid is NULL.\r
@@ -802,7 +809,8 @@ FindVariable (
   IN  CHAR16                  *VariableName,\r
   IN  EFI_GUID                *VendorGuid,\r
   OUT VARIABLE_POINTER_TRACK  *PtrTrack,\r
-  IN  VARIABLE_GLOBAL         *Global\r
+  IN  VARIABLE_GLOBAL         *Global,\r
+  IN  BOOLEAN                 IgnoreRtCheck\r
   )\r
 {\r
   EFI_STATUS              Status;\r
@@ -834,7 +842,7 @@ FindVariable (
     PtrTrack->EndPtr   = GetEndPointer   (VariableStoreHeader[Type]);\r
     PtrTrack->Volatile = (BOOLEAN) (Type == VariableStoreTypeVolatile);\r
 \r
-    Status = FindVariableEx (VariableName, VendorGuid, PtrTrack);\r
+    Status = FindVariableEx (VariableName, VendorGuid, IgnoreRtCheck, PtrTrack);\r
     if (!EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
@@ -1234,7 +1242,7 @@ 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);\r
+    Status = FindVariable (L"PlatformLang", &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
     if (!EFI_ERROR (Status)) {\r
       //\r
       // Update Lang\r
@@ -1243,7 +1251,7 @@ AutoUpdateLangVariable (
       Data         = GetVariableDataPtr (Variable.CurrPtr);\r
       DataSize     = Variable.CurrPtr->DataSize;\r
     } else {\r
-      Status = FindVariable (L"Lang", &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal);\r
+      Status = FindVariable (L"Lang", &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
       if (!EFI_ERROR (Status)) {\r
         //\r
         // Update PlatformLang\r
@@ -1288,7 +1296,7 @@ AutoUpdateLangVariable (
         //\r
         // Successfully convert PlatformLang to Lang, and set the BestLang value into Lang variable simultaneously.\r
         //\r
-        FindVariable (L"Lang", &gEfiGlobalVariableGuid, &Variable, (VARIABLE_GLOBAL *)mVariableModuleGlobal);\r
+        FindVariable (L"Lang", &gEfiGlobalVariableGuid, &Variable, (VARIABLE_GLOBAL *)mVariableModuleGlobal, FALSE);\r
 \r
         Status = UpdateVariable (L"Lang", &gEfiGlobalVariableGuid, BestLang,\r
                                  ISO_639_2_ENTRY_SIZE + 1, Attributes, &Variable);\r
@@ -1322,7 +1330,7 @@ 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);\r
+        FindVariable (L"PlatformLang", &gEfiGlobalVariableGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
 \r
         Status = UpdateVariable (L"PlatformLang", &gEfiGlobalVariableGuid, BestPlatformLang, \r
                                  AsciiStrSize (BestPlatformLang), Attributes, &Variable);\r
@@ -1418,9 +1426,9 @@ UpdateVariable (
         goto Done;\r
       }\r
       //\r
-      // Only variable that have NV attributes can be updated/deleted in Runtime.\r
+      // Only variable that have NV|RT attributes can be updated/deleted in Runtime.\r
       //\r
-      if ((Variable->CurrPtr->Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) {\r
+      if (((Variable->CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0) || ((Variable->CurrPtr->Attributes & EFI_VARIABLE_NON_VOLATILE) == 0)) {\r
         Status = EFI_INVALID_PARAMETER;\r
         goto Done;      \r
       }\r
@@ -1789,7 +1797,7 @@ VariableServiceGetVariable (
 \r
   AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
   \r
-  Status = FindVariable (VariableName, VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal);\r
+  Status = FindVariable (VariableName, VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
   if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {\r
     goto Done;\r
   }\r
@@ -1864,7 +1872,7 @@ VariableServiceGetNextVariableName (
 \r
   AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r
 \r
-  Status = FindVariable (VariableName, VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal);\r
+  Status = FindVariable (VariableName, VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r
   if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {\r
     goto Done;\r
   }\r
@@ -1941,6 +1949,7 @@ VariableServiceGetNextVariableName (
           Status = FindVariableEx (\r
                      GetVariableNamePtr (Variable.CurrPtr),\r
                      &Variable.CurrPtr->VendorGuid,\r
+                     FALSE,\r
                      &VariableInHob\r
                      );\r
           if (!EFI_ERROR (Status)) {\r
@@ -2079,7 +2088,12 @@ VariableServiceSetVariable (
   //\r
   // Check whether the input variable is already existed.\r
   //\r
-  FindVariable (VariableName, VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal);\r
+  Status = FindVariable (VariableName, VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, TRUE);\r
+  if (!EFI_ERROR (Status)) {\r
+    if (((Variable.CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0) && AtRuntime ()) {\r
+      return EFI_WRITE_PROTECTED;\r
+    }\r
+  }\r
 \r
   //\r
   // Hook the operation of setting PlatformLangCodes/PlatformLang and LangCodes/Lang.\r
index 22ded16819077a34b5b1a7927fc751ca9c349a48..4c88eb6ff69a2007ecd9b67fa7e8ecea33256d3d 100644 (file)
@@ -720,7 +720,8 @@ Reclaim (
 \r
   @param[in]       VariableName        Name of the variable to be found\r
   @param[in]       VendorGuid          Vendor GUID to be found.\r
-  @param[in]       IgnoreRtAttribute   Ignore RUNTIME_ACCESS attribute when searching variable.\r
+  @param[in]       IgnoreRtCheck       Ignore EFI_VARIABLE_RUNTIME_ACCESS attribute\r
+                                       check at runtime when searching variable.\r
   @param[in, out]  PtrTrack            Variable Track Pointer structure that contains Variable Information.\r
 \r
   @retval          EFI_SUCCESS         Variable found successfully\r
@@ -730,7 +731,7 @@ EFI_STATUS
 FindVariableEx (\r
   IN     CHAR16                  *VariableName,\r
   IN     EFI_GUID                *VendorGuid,\r
-  IN     BOOLEAN                 IgnoreRtAttribute,\r
+  IN     BOOLEAN                 IgnoreRtCheck,\r
   IN OUT VARIABLE_POINTER_TRACK  *PtrTrack\r
   )\r
 {\r
@@ -749,7 +750,7 @@ FindVariableEx (
     if (PtrTrack->CurrPtr->State == VAR_ADDED ||\r
         PtrTrack->CurrPtr->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)\r
        ) {\r
-      if (IgnoreRtAttribute || !AtRuntime () || ((PtrTrack->CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) != 0)) {\r
+      if (IgnoreRtCheck || !AtRuntime () || ((PtrTrack->CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) != 0)) {\r
         if (VariableName[0] == 0) {\r
           if (PtrTrack->CurrPtr->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {\r
             InDeletedVariable   = PtrTrack->CurrPtr;\r
@@ -785,9 +786,9 @@ FindVariableEx (
   This code finds variable in storage blocks of volatile and non-volatile storage areas.\r
   If VariableName is an empty string, then we just return the first\r
   qualified variable without comparing VariableName and VendorGuid.\r
-  If IgnoreRtAttribute is TRUE, then we ignore the EFI_VARIABLE_RUNTIME_ACCESS Attribute\r
-  when searching existing variable, only VariableName and VendorGuid are compared.\r
-  Otherwise, variables with EFI_VARIABLE_RUNTIME_ACCESS are not visible at runtime.\r
+  If IgnoreRtCheck is TRUE, then we ignore the EFI_VARIABLE_RUNTIME_ACCESS attribute check\r
+  at runtime when searching existing variable, only VariableName and VendorGuid are compared.\r
+  Otherwise, variables without EFI_VARIABLE_RUNTIME_ACCESS are not visible at runtime.\r
 \r
   @param[in]   VariableName           Name of the variable to be found.\r
   @param[in]   VendorGuid             Vendor GUID to be found.\r
@@ -796,7 +797,8 @@ FindVariableEx (
   @param[in]   Global                 Pointer to VARIABLE_GLOBAL structure, including\r
                                       base of volatile variable storage area, base of\r
                                       NV variable storage area, and a lock.\r
-  @param[in]   IgnoreRtAttribute      Ignore RUNTIME_ACCESS attribute when searching variable.\r
+  @param[in]   IgnoreRtCheck          Ignore EFI_VARIABLE_RUNTIME_ACCESS attribute\r
+                                      check at runtime when searching variable.\r
 \r
   @retval EFI_INVALID_PARAMETER       If VariableName is not an empty string, while\r
                                       VendorGuid is NULL.\r
@@ -810,7 +812,7 @@ FindVariable (
   IN  EFI_GUID                *VendorGuid,\r
   OUT VARIABLE_POINTER_TRACK  *PtrTrack,\r
   IN  VARIABLE_GLOBAL         *Global,\r
-  IN  BOOLEAN                 IgnoreRtAttribute\r
+  IN  BOOLEAN                 IgnoreRtCheck\r
   )\r
 {\r
   EFI_STATUS              Status;\r
@@ -842,7 +844,7 @@ FindVariable (
     PtrTrack->EndPtr   = GetEndPointer   (VariableStoreHeader[Type]);\r
     PtrTrack->Volatile = (BOOLEAN) (Type == VariableStoreTypeVolatile);\r
 \r
-    Status = FindVariableEx (VariableName, VendorGuid, IgnoreRtAttribute, PtrTrack);\r
+    Status = FindVariableEx (VariableName, VendorGuid, IgnoreRtCheck, PtrTrack);\r
     if (!EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
index d58203739fb5e3a613caa55c71314388ed59dbad..be3e632a2a771d8c89189a194705481a6266bbd6 100644 (file)
@@ -120,9 +120,9 @@ FtwVariableSpace (
   This code finds variable in storage blocks of volatile and non-volatile storage areas.\r
   If VariableName is an empty string, then we just return the first\r
   qualified variable without comparing VariableName and VendorGuid.\r
-  If IgnoreRtAttribute is TRUE, then we ignore the EFI_VARIABLE_RUNTIME_ACCESS Attribute\r
-  when searching existing variable, only VariableName and VendorGuid are compared.\r
-  Otherwise, variables with EFI_VARIABLE_RUNTIME_ACCESS are not visible at runtime.\r
+  If IgnoreRtCheck is TRUE, then we ignore the EFI_VARIABLE_RUNTIME_ACCESS attribute check\r
+  at runtime when searching existing variable, only VariableName and VendorGuid are compared.\r
+  Otherwise, variables without EFI_VARIABLE_RUNTIME_ACCESS are not visible at runtime.\r
 \r
   @param[in]   VariableName           Name of the variable to be found.\r
   @param[in]   VendorGuid             Vendor GUID to be found.\r
@@ -131,7 +131,8 @@ FtwVariableSpace (
   @param[in]   Global                 Pointer to VARIABLE_GLOBAL structure, including\r
                                       base of volatile variable storage area, base of\r
                                       NV variable storage area, and a lock.\r
-  @param[in]   IgnoreRtAttribute      Ignore RUNTIME_ACCESS attribute when searching variable.\r
+  @param[in]   IgnoreRtCheck          Ignore EFI_VARIABLE_RUNTIME_ACCESS attribute\r
+                                      check at runtime when searching variable.\r
 \r
   @retval EFI_INVALID_PARAMETER       If VariableName is not an empty string, while\r
                                       VendorGuid is NULL.\r
@@ -145,7 +146,7 @@ FindVariable (
   IN  EFI_GUID                *VendorGuid,\r
   OUT VARIABLE_POINTER_TRACK  *PtrTrack,\r
   IN  VARIABLE_GLOBAL         *Global,\r
-  IN  BOOLEAN                 IgnoreRtAttribute\r
+  IN  BOOLEAN                 IgnoreRtCheck\r
   );\r
 \r
 /**\r