#include <Library/DebugLib.h>\r
#include <Library/SafeIntLib.h>\r
#include <Library/MmServicesTableLib.h>\r
-#include <Library/SmmMemLib.h>\r
#include <Library/BaseMemoryLib.h>\r
#include <Library/MemoryAllocationLib.h>\r
\r
\r
#include <Guid/VarCheckPolicyMmi.h>\r
\r
+#include "VarCheckPolicyLib.h"\r
+\r
//================================================\r
// As a VarCheck library, we're linked into the VariableServices\r
// and may not be able to call them indirectly. To get around this,\r
// Make sure that the buffer does not overlap SMM.\r
// This should be covered by the SmiManage infrastructure, but just to be safe...\r
InternalCommBufferSize = *CommBufferSize;\r
- if (InternalCommBufferSize > VAR_CHECK_POLICY_MM_COMM_BUFFER_SIZE || !SmmIsBufferOutsideSmmValid((UINTN)CommBuffer, (UINT64)InternalCommBufferSize)) {\r
+ if (InternalCommBufferSize > VAR_CHECK_POLICY_MM_COMM_BUFFER_SIZE ||\r
+ !VarCheckPolicyIsBufferOutsideValid((UINTN)CommBuffer, (UINT64)InternalCommBufferSize)) {\r
DEBUG ((DEBUG_ERROR, "%a - Invalid CommBuffer supplied! 0x%016lX[0x%016lX]\n", __FUNCTION__, CommBuffer, InternalCommBufferSize));\r
return EFI_INVALID_PARAMETER;\r
}\r
Constructor function of VarCheckPolicyLib to register VarCheck handler and\r
SW MMI handlers.\r
\r
- @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
- @param[in] SystemTable A pointer to the EFI System Table.\r
-\r
@retval EFI_SUCCESS The constructor executed correctly.\r
\r
**/\r
EFI_STATUS\r
EFIAPI\r
-VarCheckPolicyLibConstructor (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
+VarCheckPolicyLibCommonConstructor (\r
+ VOID\r
)\r
{\r
EFI_STATUS Status;\r
--- /dev/null
+/** @file -- VarCheckPolicyLib.h\r
+This internal header file defines the common interface of constructor for\r
+VarCheckPolicyLib.\r
+\r
+Copyright (c) Microsoft Corporation. All rights reserved.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef _VAR_CHECK_POLICY_LIB_H_\r
+#define _VAR_CHECK_POLICY_LIB_H_\r
+\r
+/**\r
+ Common constructor function of VarCheckPolicyLib to register VarCheck handler\r
+ and SW MMI handlers.\r
+\r
+ @retval EFI_SUCCESS The constructor executed correctly.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VarCheckPolicyLibCommonConstructor (\r
+ VOID\r
+ );\r
+\r
+/**\r
+ This function is wrapper function to validate the buffer.\r
+\r
+ @param Buffer The buffer start address to be checked.\r
+ @param Length The buffer length to be checked.\r
+\r
+ @retval TRUE This buffer is valid per processor architecture and not overlap with SMRAM/MMRAM.\r
+ @retval FALSE This buffer is not valid per processor architecture or overlap with SMRAM/MMRAM.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+VarCheckPolicyIsBufferOutsideValid (\r
+ IN EFI_PHYSICAL_ADDRESS Buffer,\r
+ IN UINT64 Length\r
+ );\r
+\r
+#endif // _VAR_CHECK_POLICY_LIB_H_\r
MODULE_TYPE = DXE_RUNTIME_DRIVER\r
VERSION_STRING = 1.0\r
LIBRARY_CLASS = NULL|DXE_RUNTIME_DRIVER DXE_SMM_DRIVER\r
- CONSTRUCTOR = VarCheckPolicyLibConstructor\r
+ CONSTRUCTOR = VarCheckPolicyLibTraditionalConstructor\r
\r
\r
[Sources]\r
VarCheckPolicyLib.c\r
+ VarCheckPolicyLibTraditional.c\r
+ VarCheckPolicyLib.h\r
\r
\r
[Packages]\r
BaseLib\r
DebugLib\r
BaseMemoryLib\r
- DxeServicesLib\r
MemoryAllocationLib\r
VarCheckLib\r
VariablePolicyLib\r
--- /dev/null
+/** @file -- VarCheckPolicyLibStandaloneMm.c\r
+This is an instance of a VarCheck lib constructor for Standalone MM.\r
+\r
+Copyright (c) Microsoft Corporation. All rights reserved.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Library/StandaloneMmMemLib.h>\r
+\r
+#include "VarCheckPolicyLib.h"\r
+\r
+/**\r
+ Standalone MM constructor function of VarCheckPolicyLib to invoke common\r
+ constructor routine.\r
+\r
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
+ @param[in] SystemTable A pointer to the EFI System Table.\r
+\r
+ @retval EFI_SUCCESS The constructor executed correctly.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VarCheckPolicyLibStandaloneConstructor (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_MM_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ return VarCheckPolicyLibCommonConstructor ();\r
+}\r
+\r
+/**\r
+ This function is wrapper function to validate the buffer.\r
+\r
+ @param Buffer The buffer start address to be checked.\r
+ @param Length The buffer length to be checked.\r
+\r
+ @retval TRUE This buffer is valid per processor architectureand not overlap with MMRAM.\r
+ @retval FALSE This buffer is not valid per processor architecture or overlap with MMRAM.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+VarCheckPolicyIsBufferOutsideValid (\r
+ IN EFI_PHYSICAL_ADDRESS Buffer,\r
+ IN UINT64 Length\r
+ )\r
+{\r
+ return MmIsBufferOutsideMmValid (Buffer, Length);\r
+}\r
--- /dev/null
+## @file VarCheckPolicyLibStandaloneMm.inf\r
+# This is an instance of a VarCheck lib that leverages the business logic behind\r
+# the VariablePolicy code to make its decisions.\r
+#\r
+#\r
+# Copyright (c) Microsoft Corporation. All rights reserved.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = VarCheckPolicyLibStandaloneMm\r
+ FILE_GUID = 44B09E3D-5EDA-4673-ABCF-C8AE4560C8EC\r
+ MODULE_TYPE = MM_STANDALONE\r
+ PI_SPECIFICATION_VERSION = 0x00010032\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = NULL|MM_STANDALONE\r
+ CONSTRUCTOR = VarCheckPolicyLibStandaloneConstructor\r
+\r
+\r
+[Sources]\r
+ VarCheckPolicyLib.c\r
+ VarCheckPolicyLibStandaloneMm.c\r
+ VarCheckPolicyLib.h\r
+\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ MdeModulePkg/MdeModulePkg.dec\r
+ StandaloneMmPkg/StandaloneMmPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+ BaseLib\r
+ DebugLib\r
+ BaseMemoryLib\r
+ MemLib\r
+ MemoryAllocationLib\r
+ VarCheckLib\r
+ VariablePolicyLib\r
+ VariablePolicyHelperLib\r
+ SafeIntLib\r
+ MmServicesTableLib\r
+\r
+[Guids]\r
+ gVarCheckPolicyLibMmiHandlerGuid ## CONSUME ## Used to register for MM Communication events.\r
--- /dev/null
+/** @file -- VarCheckPolicyLibTraditional.c\r
+This is an instance of a VarCheck lib constructor for traditional SMM.\r
+\r
+Copyright (c) Microsoft Corporation. All rights reserved.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Library/SmmMemLib.h>\r
+\r
+#include "VarCheckPolicyLib.h"\r
+\r
+/**\r
+ Traditional constructor function of VarCheckPolicyLib to invoke common\r
+ constructor routine.\r
+\r
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
+ @param[in] SystemTable A pointer to the EFI System Table.\r
+\r
+ @retval EFI_SUCCESS The constructor executed correctly.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VarCheckPolicyLibTraditionalConstructor (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ return VarCheckPolicyLibCommonConstructor ();\r
+}\r
+\r
+/**\r
+ This function is wrapper function to validate the buffer.\r
+\r
+ @param Buffer The buffer start address to be checked.\r
+ @param Length The buffer length to be checked.\r
+\r
+ @retval TRUE This buffer is valid per processor architecture and not overlap with SMRAM.\r
+ @retval FALSE This buffer is not valid per processor architecture or overlap with SMRAM.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+VarCheckPolicyIsBufferOutsideValid (\r
+ IN EFI_PHYSICAL_ADDRESS Buffer,\r
+ IN UINT64 Length\r
+ )\r
+{\r
+ return SmmIsBufferOutsideSmmValid (Buffer, Length);\r
+}\r
MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf\r
MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLibRuntimeDxe.inf\r
MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLib.inf\r
+ MdeModulePkg/Library/VarCheckPolicyLib/VarCheckPolicyLibStandaloneMm.inf\r
MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf\r
MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLib.inf\r
MdeModulePkg/Library/VarCheckPcdLib/VarCheckPcdLib.inf\r