]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/Variable/RuntimeDxe: introduce PcdMaxVolatileVariableSize
authorLaszlo Ersek <lersek@redhat.com>
Wed, 28 Mar 2018 13:55:42 +0000 (15:55 +0200)
committerLaszlo Ersek <lersek@redhat.com>
Fri, 30 Mar 2018 19:17:07 +0000 (21:17 +0200)
The variable driver doesn't distinguish "non-volatile non-authenticated"
variables from "volatile non-authenticated" variables, when checking
individual variable sizes against the permitted maximum.
PcdMaxVariableSize covers both kinds.

This prevents volatile non-authenticated variables from carrying large
data between UEFI drivers, despite having no flash impact. One example is
EFI_TLS_CA_CERTIFICATE_VARIABLE, which platforms might want to create as
volatile on every boot: the certificate list can be several hundred KB in
size.

Introduce PcdMaxVolatileVariableSize to represent the limit on individual
volatile non-authenticated variables. The default value is zero, which
makes Variable/RuntimeDxe fall back to PcdMaxVariableSize (i.e. the
current behavior). This is similar to the PcdMaxAuthVariableSize fallback.

Whenever the size limit is enforced, consult MaxVolatileVariableSize as
the last option, after checking
- MaxAuthVariableSize for VARIABLE_ATTRIBUTE_AT_AW,
- and MaxVariableSize for EFI_VARIABLE_NON_VOLATILE.

EFI_VARIABLE_HARDWARE_ERROR_RECORD is always handled separately; it always
takes priority over the three cases listed above.

Introduce the GetMaxVariableSize() helper to consider
PcdMaxVolatileVariableSize, in addition to
GetNonVolatileMaxVariableSize(). GetNonVolatileMaxVariableSize() is
currently called at three sites, and two of those need to start using
GetMaxVariableSize() instead:
- VariableServiceInitialize() [VariableSmm.c]: the SMM comms buffer must
  accommodate all kinds of variables,
- VariableCommonInitialize() [Variable.c]: the preallocated scratch space
  must also accommodate all kinds of variables,
- InitNonVolatileVariableStore() [Variable.c] can continue using
  GetNonVolatileMaxVariableSize().

Don't modify the ReclaimForOS() function as it is specific to non-volatile
variables and should ignore PcdMaxVolatileVariableSize.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Gary Lin <glin@suse.com>
Tested-by: Gary Lin <glin@suse.com>
[lersek@redhat.com: set MaxVolatileVariableSize where Star suggested]
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/MdeModulePkg.dec
MdeModulePkg/MdeModulePkg.uni
MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf

index 5d561ff48495323c5c7cd3ea48b28e8f7593fa18..cc397185f7b90d7c421d60f3b5e819839a474188 100644 (file)
   # @Prompt Maximum authenticated variable size.\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x00|UINT32|0x30000009\r
 \r
   # @Prompt Maximum authenticated variable size.\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x00|UINT32|0x30000009\r
 \r
+  ## The maximum size of a single non-authenticated volatile variable.\r
+  # The default value is 0 for compatibility: in that case, the maximum\r
+  # non-authenticated volatile variable size remains specified by\r
+  # PcdMaxVariableSize. Only the MdeModulePkg/Universal/Variable/RuntimeDxe\r
+  # driver supports this PCD.\r
+  # @Prompt Maximum non-authenticated volatile variable size.\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize|0x00|UINT32|0x3000000a\r
+\r
   ## The maximum size of single hardware error record variable.<BR><BR>\r
   # In IA32/X64 platforms, this value should be larger than 1KB.<BR>\r
   # In IA64 platforms, this value should be larger than 128KB.<BR>\r
   ## The maximum size of single hardware error record variable.<BR><BR>\r
   # In IA32/X64 platforms, this value should be larger than 1KB.<BR>\r
   # In IA64 platforms, this value should be larger than 128KB.<BR>\r
index f3fa616438b0e37ea6feccbee6c4ab1f9d8f1035..080b8a62c0456950030086d7f2d9ef7bb4f06594 100644 (file)
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdMaxAuthVariableSize_HELP  #language en-US "The maximum size of a single authenticated variable."\r
                                                                                         "The value is 0 as default for compatibility that maximum authenticated variable size is specified by PcdMaxVariableSize."\r
 \r
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdMaxAuthVariableSize_HELP  #language en-US "The maximum size of a single authenticated variable."\r
                                                                                         "The value is 0 as default for compatibility that maximum authenticated variable size is specified by PcdMaxVariableSize."\r
 \r
+#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdMaxVolatileVariableSize_PROMPT  #language en-US "The maximum size of a single non-authenticated volatile variable."\r
+\r
+#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdMaxVolatileVariableSize_HELP  #language en-US "The maximum size of a single non-authenticated volatile variable.<BR><BR>\n"\r
+                                                                                            "The default value is 0 for compatibility: in that case, the maximum "\r
+                                                                                            "non-authenticated volatile variable size remains specified by "\r
+                                                                                            "PcdMaxVariableSize.<BR>\n"\r
+                                                                                            "Only the MdeModulePkg/Universal/Variable/RuntimeDxe driver supports this PCD.<BR>"\r
+\r
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdMaxHardwareErrorVariableSize_PROMPT  #language en-US "Maximum HwErr variable size"\r
 \r
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdMaxHardwareErrorVariableSize_HELP  #language en-US "The maximum size of single hardware error record variable.<BR><BR>\n"\r
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdMaxHardwareErrorVariableSize_PROMPT  #language en-US "Maximum HwErr variable size"\r
 \r
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdMaxHardwareErrorVariableSize_HELP  #language en-US "The maximum size of single hardware error record variable.<BR><BR>\n"\r
index c11842b5c3ba742f440eaf474234c4deec9c5c27..6caf603b3d305f41b43c45c966a6957a014bff31 100644 (file)
@@ -2345,12 +2345,14 @@ UpdateVariable (
         CopyMem (BufferForMerge, (UINT8 *) ((UINTN) CacheVariable->CurrPtr + DataOffset), DataSizeOfVariable (CacheVariable->CurrPtr));\r
 \r
         //\r
         CopyMem (BufferForMerge, (UINT8 *) ((UINTN) CacheVariable->CurrPtr + DataOffset), DataSizeOfVariable (CacheVariable->CurrPtr));\r
 \r
         //\r
-        // Set Max Common/Auth Variable Data Size as default MaxDataSize.\r
+        // Set Max Auth/Non-Volatile/Volatile Variable Data Size as default MaxDataSize.\r
         //\r
         if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) != 0) {\r
           MaxDataSize = mVariableModuleGlobal->MaxAuthVariableSize - DataOffset;\r
         //\r
         if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) != 0) {\r
           MaxDataSize = mVariableModuleGlobal->MaxAuthVariableSize - DataOffset;\r
-        } else {\r
+        } else if ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0) {\r
           MaxDataSize = mVariableModuleGlobal->MaxVariableSize - DataOffset;\r
           MaxDataSize = mVariableModuleGlobal->MaxVariableSize - DataOffset;\r
+        } else {\r
+          MaxDataSize = mVariableModuleGlobal->MaxVolatileVariableSize - DataOffset;\r
         }\r
 \r
         //\r
         }\r
 \r
         //\r
@@ -3218,16 +3220,20 @@ VariableServiceSetVariable (
   } else {\r
     //\r
     //  The size of the VariableName, including the Unicode Null in bytes plus\r
   } else {\r
     //\r
     //  The size of the VariableName, including the Unicode Null in bytes plus\r
-    //  the DataSize is limited to maximum size of Max(Auth)VariableSize bytes.\r
+    //  the DataSize is limited to maximum size of Max(Auth|Volatile)VariableSize bytes.\r
     //\r
     if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) != 0) {\r
       if (StrSize (VariableName) + PayloadSize > mVariableModuleGlobal->MaxAuthVariableSize - GetVariableHeaderSize ()) {\r
         return EFI_INVALID_PARAMETER;\r
       }\r
     //\r
     if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) != 0) {\r
       if (StrSize (VariableName) + PayloadSize > mVariableModuleGlobal->MaxAuthVariableSize - GetVariableHeaderSize ()) {\r
         return EFI_INVALID_PARAMETER;\r
       }\r
-    } else {\r
+    } else if ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0) {\r
       if (StrSize (VariableName) + PayloadSize > mVariableModuleGlobal->MaxVariableSize - GetVariableHeaderSize ()) {\r
         return EFI_INVALID_PARAMETER;\r
       }\r
       if (StrSize (VariableName) + PayloadSize > mVariableModuleGlobal->MaxVariableSize - GetVariableHeaderSize ()) {\r
         return EFI_INVALID_PARAMETER;\r
       }\r
+    } else {\r
+      if (StrSize (VariableName) + PayloadSize > mVariableModuleGlobal->MaxVolatileVariableSize - GetVariableHeaderSize ()) {\r
+        return EFI_INVALID_PARAMETER;\r
+      }\r
     }\r
   }\r
 \r
     }\r
   }\r
 \r
@@ -3399,12 +3405,14 @@ VariableServiceQueryVariableInfoInternal (
     }\r
 \r
     //\r
     }\r
 \r
     //\r
-    // Let *MaximumVariableSize be Max(Auth)VariableSize with the exception of the variable header size.\r
+    // Let *MaximumVariableSize be Max(Auth|Volatile)VariableSize with the exception of the variable header size.\r
     //\r
     if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) != 0) {\r
       *MaximumVariableSize = mVariableModuleGlobal->MaxAuthVariableSize - GetVariableHeaderSize ();\r
     //\r
     if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) != 0) {\r
       *MaximumVariableSize = mVariableModuleGlobal->MaxAuthVariableSize - GetVariableHeaderSize ();\r
-    } else {\r
+    } else if ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0) {\r
       *MaximumVariableSize = mVariableModuleGlobal->MaxVariableSize - GetVariableHeaderSize ();\r
       *MaximumVariableSize = mVariableModuleGlobal->MaxVariableSize - GetVariableHeaderSize ();\r
+    } else {\r
+      *MaximumVariableSize = mVariableModuleGlobal->MaxVolatileVariableSize - GetVariableHeaderSize ();\r
     }\r
   }\r
 \r
     }\r
   }\r
 \r
@@ -3657,6 +3665,30 @@ GetNonVolatileMaxVariableSize (
   }\r
 }\r
 \r
   }\r
 }\r
 \r
+/**\r
+  Get maximum variable size, covering both non-volatile and volatile variables.\r
+\r
+  @return Maximum variable size.\r
+\r
+**/\r
+UINTN\r
+GetMaxVariableSize (\r
+  VOID\r
+  )\r
+{\r
+  UINTN MaxVariableSize;\r
+\r
+  MaxVariableSize = GetNonVolatileMaxVariableSize();\r
+  //\r
+  // The condition below fails implicitly if PcdMaxVolatileVariableSize equals\r
+  // the default zero value.\r
+  //\r
+  if (MaxVariableSize < PcdGet32 (PcdMaxVolatileVariableSize)) {\r
+    MaxVariableSize = PcdGet32 (PcdMaxVolatileVariableSize);\r
+  }\r
+  return MaxVariableSize;\r
+}\r
+\r
 /**\r
   Init non-volatile variable store.\r
 \r
 /**\r
   Init non-volatile variable store.\r
 \r
@@ -4225,10 +4257,14 @@ VariableCommonInitialize (
     }\r
   }\r
 \r
     }\r
   }\r
 \r
+  mVariableModuleGlobal->MaxVolatileVariableSize = ((PcdGet32 (PcdMaxVolatileVariableSize) != 0) ?\r
+                                                    PcdGet32 (PcdMaxVolatileVariableSize) :\r
+                                                    mVariableModuleGlobal->MaxVariableSize\r
+                                                    );\r
   //\r
   // Allocate memory for volatile variable store, note that there is a scratch space to store scratch data.\r
   //\r
   //\r
   // Allocate memory for volatile variable store, note that there is a scratch space to store scratch data.\r
   //\r
-  ScratchSize = GetNonVolatileMaxVariableSize ();\r
+  ScratchSize = GetMaxVariableSize ();\r
   mVariableModuleGlobal->ScratchBufferSize = ScratchSize;\r
   VolatileVariableStore = AllocateRuntimePool (PcdGet32 (PcdVariableStoreSize) + ScratchSize);\r
   if (VolatileVariableStore == NULL) {\r
   mVariableModuleGlobal->ScratchBufferSize = ScratchSize;\r
   VolatileVariableStore = AllocateRuntimePool (PcdGet32 (PcdVariableStoreSize) + ScratchSize);\r
   if (VolatileVariableStore == NULL) {\r
index b35e8ab912733114cfbe3d7f9e1a1bc4ad0ac0e0..938eb5de61fa48234d32a090a952fb076c562493 100644 (file)
@@ -101,6 +101,7 @@ typedef struct {
   UINTN           HwErrVariableTotalSize;\r
   UINTN           MaxVariableSize;\r
   UINTN           MaxAuthVariableSize;\r
   UINTN           HwErrVariableTotalSize;\r
   UINTN           MaxVariableSize;\r
   UINTN           MaxAuthVariableSize;\r
+  UINTN           MaxVolatileVariableSize;\r
   UINTN           ScratchBufferSize;\r
   CHAR8           *PlatformLangCodes;\r
   CHAR8           *LangCodes;\r
   UINTN           ScratchBufferSize;\r
   CHAR8           *PlatformLangCodes;\r
   CHAR8           *LangCodes;\r
@@ -460,6 +461,17 @@ GetNonVolatileMaxVariableSize (
   VOID\r
   );\r
 \r
   VOID\r
   );\r
 \r
+/**\r
+  Get maximum variable size, covering both non-volatile and volatile variables.\r
+\r
+  @return Maximum variable size.\r
+\r
+**/\r
+UINTN\r
+GetMaxVariableSize (\r
+  VOID\r
+  );\r
+\r
 /**\r
   Initializes variable write service after FVB was ready.\r
 \r
 /**\r
   Initializes variable write service after FVB was ready.\r
 \r
index e840fc9bff40fd69f6901b87301a5cb4706bfd65..2d0a172ece3518d237aac0ccd8f06951dfcbbafe 100644 (file)
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64    ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize                 ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize             ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64    ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize                 ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize             ## CONSUMES\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize         ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize    ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize               ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize                ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize    ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize               ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize                ## CONSUMES\r
index 8d73b6edee5118f2a14ae1df685a3327daa55fae..e495d971a08b1d8df69fddf05d92c9e80d9e40fd 100644 (file)
@@ -955,7 +955,7 @@ VariableServiceInitialize (
                     );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
                     );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  mVariableBufferPayloadSize = GetNonVolatileMaxVariableSize () +\r
+  mVariableBufferPayloadSize = GetMaxVariableSize () +\r
                                OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) - GetVariableHeaderSize ();\r
 \r
   Status = gSmst->SmmAllocatePool (\r
                                OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) - GetVariableHeaderSize ();\r
 \r
   Status = gSmst->SmmAllocatePool (\r
index 69966f0d37ee3f400d8760fd289bf232e7f61476..dbb0674a46adeb3216667b9f4052bf0d3bfb43dc 100644 (file)
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64     ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize                  ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize              ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64     ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize                  ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize              ## CONSUMES\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize          ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize     ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize                ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize                 ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize     ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize                ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize                 ## CONSUMES\r