UINTN mFullSmramRangeCount;\r
EFI_SMRAM_DESCRIPTOR *mFullSmramRanges;\r
\r
-//\r
-// Maximum support address used to check input CommunicationBuffer\r
-//\r
-UINTN mMaximumSupportAddress = 0;\r
-\r
/**\r
Place holder function until all the SMM System Table Service are available.\r
\r
return Status;\r
}\r
\r
-/**\r
- Caculate and save the maximum support address.\r
-\r
-**/\r
-VOID\r
-CaculateMaximumSupportAddress (\r
- VOID\r
- )\r
-{\r
- VOID *Hob;\r
- UINT32 RegEax;\r
- UINT8 PhysicalAddressBits;\r
-\r
- //\r
- // Get physical address bits supported.\r
- //\r
- Hob = GetFirstHob (EFI_HOB_TYPE_CPU);\r
- if (Hob != NULL) {\r
- PhysicalAddressBits = ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace;\r
- } else {\r
- AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);\r
- if (RegEax >= 0x80000008) {\r
- AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);\r
- PhysicalAddressBits = (UINT8) RegEax;\r
- } else {\r
- PhysicalAddressBits = 36;\r
- }\r
- }\r
- //\r
- // IA-32e paging translates 48-bit linear addresses to 52-bit physical addresses.\r
- //\r
- ASSERT (PhysicalAddressBits <= 52);\r
- if (PhysicalAddressBits > 48) {\r
- PhysicalAddressBits = 48;\r
- }\r
- \r
- //\r
- // Save the maximum support address in one global variable \r
- //\r
- mMaximumSupportAddress = (UINTN) (LShiftU64 (1, PhysicalAddressBits) - 1);\r
- DEBUG ((EFI_D_INFO, "mMaximumSupportAddress = 0x%lx\n", mMaximumSupportAddress));\r
-}\r
-\r
-/**\r
- Check if input buffer is in valid address scope or not.\r
-\r
- @param[in] Pointer Pointer to the input buffer.\r
- @param[in] BufferSize Input buffer size in bytes.\r
-\r
- @retval TRUE The input buffer is in valid address scope. \r
- @retval FALSE The input buffer is not in valid address scope. \r
-\r
-**/\r
-BOOLEAN\r
-IsValidPointer (\r
- IN VOID *Pointer,\r
- IN UINTN BufferSize\r
- )\r
-{\r
- if ((UINTN) Pointer > mMaximumSupportAddress) {\r
- return FALSE;\r
- }\r
-\r
- if (BufferSize > (mMaximumSupportAddress - (UINTN) Pointer)) {\r
- return FALSE;\r
- }\r
-\r
- return TRUE;\r
-}\r
-\r
/**\r
The main entry point to SMM Foundation.\r
\r
//\r
// Synchronous SMI for SMM Core or request from Communicate protocol\r
//\r
- if (!IsValidPointer (gSmmCorePrivate->CommunicationBuffer, gSmmCorePrivate->BufferSize)) {\r
+ if (!SmmIsBufferOutsideSmmValid ((UINTN)gSmmCorePrivate->CommunicationBuffer, gSmmCorePrivate->BufferSize)) {\r
//\r
// If CommunicationBuffer is not in valid address scope, return EFI_INVALID_PARAMETER\r
//\r
gSmmCorePrivate->SmmEntryPoint = SmmEntryPoint;\r
\r
//\r
- // Initialize memory service using free SMRAM\r
+ // No need to initialize memory service.\r
+ // It is done in constructor of PiSmmCoreMemoryAllocationLib(),\r
+ // so that the library linked with PiSmmCore can use AllocatePool() in constuctor.\r
//\r
- SmmInitializeMemoryServices (gSmmCorePrivate->SmramRangeCount, gSmmCorePrivate->SmramRanges);\r
\r
SmramProfileInit ();\r
\r
\r
RegisterSmramProfileHandler ();\r
\r
- //\r
- // Caculate and save maximum support address used in SmmEntryPoint().\r
- //\r
- CaculateMaximumSupportAddress ();\r
-\r
return EFI_SUCCESS;\r
}\r
#include <Library/PerformanceLib.h>\r
#include <Library/TimerLib.h>\r
#include <Library/HobLib.h>\r
+#include <Library/SmmMemLib.h>\r
\r
#include "PiSmmCorePrivateData.h"\r
\r
## @file\r
# This module provide an SMM CIS compliant implementation of SMM Core.\r
#\r
-# Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
#\r
# This program and the accompanying materials\r
# are licensed and made available under the terms and conditions of the BSD License\r
PerformanceLib\r
TimerLib\r
HobLib\r
+ SmmMemLib\r
\r
[Protocols]\r
gEfiDxeSmmReadyToLockProtocolGuid ## UNDEFINED # SmiHandlerRegister\r
/** @file\r
Support routines for SMRAM profile.\r
\r
- Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2014 - 2015, 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
\r
////////////////////\r
\r
-/**\r
- This function check if the address is in SMRAM.\r
-\r
- @param Buffer the buffer address to be checked.\r
- @param Length the buffer length to be checked.\r
-\r
- @retval TRUE this address is in SMRAM.\r
- @retval FALSE this address is NOT in SMRAM.\r
-\r
-**/\r
-BOOLEAN\r
-InternalIsAddressInSmram (\r
- IN PHYSICAL_ADDRESS Buffer,\r
- IN UINT64 Length\r
- )\r
-{\r
- UINTN Index;\r
-\r
- for (Index = 0; Index < mFullSmramRangeCount; Index ++) {\r
- if (((Buffer >= mFullSmramRanges[Index].CpuStart) && (Buffer < mFullSmramRanges[Index].CpuStart + mFullSmramRanges[Index].PhysicalSize)) ||\r
- ((mFullSmramRanges[Index].CpuStart >= Buffer) && (mFullSmramRanges[Index].CpuStart < Buffer + Length))) {\r
- return TRUE;\r
- }\r
- }\r
-\r
- return FALSE;\r
-}\r
-\r
-/**\r
- This function check if the address refered by Buffer and Length is valid.\r
-\r
- @param Buffer the buffer address to be checked.\r
- @param Length the buffer length to be checked.\r
-\r
- @retval TRUE this address is valid.\r
- @retval FALSE this address is NOT valid.\r
-**/\r
-BOOLEAN\r
-InternalIsAddressValid (\r
- IN UINTN Buffer,\r
- IN UINTN Length\r
- )\r
-{\r
- if (Buffer > (MAX_ADDRESS - Length)) {\r
- //\r
- // Overflow happen\r
- //\r
- return FALSE;\r
- }\r
- if (InternalIsAddressInSmram ((PHYSICAL_ADDRESS) Buffer, (UINT64)Length)) {\r
- return FALSE;\r
- }\r
- return TRUE;\r
-}\r
-\r
/**\r
Get SMRAM profile data size.\r
\r
//\r
// Sanity check\r
//\r
- if (!InternalIsAddressValid ((UINTN) SmramProfileGetData.ProfileBuffer, (UINTN) ProfileSize)) {\r
+ if (!SmmIsBufferOutsideSmmValid ((UINTN) SmramProfileGetData.ProfileBuffer, (UINTN) ProfileSize)) {\r
DEBUG ((EFI_D_ERROR, "SmramProfileHandlerGetData: SMM ProfileBuffer in SMRAM or overflow!\n"));\r
SmramProfileParameterGetData->ProfileSize = ProfileSize;\r
SmramProfileParameterGetData->Header.ReturnStatus = (UINT64) (INT64) (INTN) EFI_ACCESS_DENIED;\r
return EFI_SUCCESS;\r
}\r
\r
- if (mSmramReadyToLock && !InternalIsAddressValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
+ if (mSmramReadyToLock && !SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
DEBUG ((EFI_D_ERROR, "SmramProfileHandler: SMM communication buffer in SMRAM or overflow!\n"));\r
return EFI_SUCCESS;\r
}\r
/** @file\r
Support routines for memory allocation routines based on SMM Core internal functions.\r
\r
- Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2006 - 2015, 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
ASSERT_EFI_ERROR (Status);\r
}\r
\r
+/**\r
+ The constructor function calls SmmInitializeMemoryServices to initialize memory in SMRAM.\r
+\r
+ @param ImageHandle The firmware allocated handle for the EFI image.\r
+ @param SystemTable A pointer to the EFI System Table.\r
+\r
+ @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PiSmmCoreMemoryAllocationLibConstructor (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ SMM_CORE_PRIVATE_DATA *SmmCorePrivate;\r
+\r
+ SmmCorePrivate = (SMM_CORE_PRIVATE_DATA *)ImageHandle;\r
+ //\r
+ // Initialize memory service using free SMRAM\r
+ //\r
+ SmmInitializeMemoryServices (SmmCorePrivate->SmramRangeCount, SmmCorePrivate->SmramRanges);\r
+ return EFI_SUCCESS;\r
+}\r
# for memory allocation instead of using SMM System Table servces in an indirect way.\r
# It is assumed that this library instance must be linked with SMM Cre in this package. \r
#\r
-# Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
#\r
# This program and the accompanying materials\r
# are licensed and made available under the terms and conditions of the BSD License\r
VERSION_STRING = 1.0\r
PI_SPECIFICATION_VERSION = 0x0001000A\r
LIBRARY_CLASS = MemoryAllocationLib|SMM_CORE\r
- \r
+ CONSTRUCTOR = PiSmmCoreMemoryAllocationLibConstructor\r
+\r
#\r
# The following information is for reference only and not required by the build tools.\r
#\r
This header file borrows the PiSmmCore Memory Allocation services as the primitive\r
for memory allocation. \r
\r
- Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2008 - 2015, 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
#ifndef _PI_SMM_CORE_MEMORY_ALLOCATION_SERVICES_H_\r
#define _PI_SMM_CORE_MEMORY_ALLOCATION_SERVICES_H_\r
\r
+typedef struct {\r
+ UINTN Signature;\r
+ ///\r
+ /// The ImageHandle passed into the entry point of the SMM IPL. This ImageHandle\r
+ /// is used by the SMM Core to fill in the ParentImageHandle field of the Loaded\r
+ /// Image Protocol for each SMM Driver that is dispatched by the SMM Core.\r
+ ///\r
+ EFI_HANDLE SmmIplImageHandle;\r
+ ///\r
+ /// The number of SMRAM ranges passed from the SMM IPL to the SMM Core. The SMM\r
+ /// Core uses these ranges of SMRAM to initialize the SMM Core memory manager.\r
+ ///\r
+ UINTN SmramRangeCount;\r
+ ///\r
+ /// A table of SMRAM ranges passed from the SMM IPL to the SMM Core. The SMM\r
+ /// Core uses these ranges of SMRAM to initialize the SMM Core memory manager.\r
+ ///\r
+ EFI_SMRAM_DESCRIPTOR *SmramRanges;\r
+} SMM_CORE_PRIVATE_DATA;\r
+\r
+/**\r
+ Called to initialize the memory service.\r
+\r
+ @param SmramRangeCount Number of SMRAM Regions\r
+ @param SmramRanges Pointer to SMRAM Descriptors\r
+\r
+**/\r
+VOID\r
+SmmInitializeMemoryServices (\r
+ IN UINTN SmramRangeCount,\r
+ IN EFI_SMRAM_DESCRIPTOR *SmramRanges\r
+ );\r
+\r
/**\r
Allocates pages from the memory map.\r
\r
\r
SmmPerformanceHandlerEx(), SmmPerformanceHandler() will receive untrusted input and do basic validation.\r
\r
-Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2015, 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
\r
SPIN_LOCK mSmmPerfLock;\r
\r
-EFI_SMRAM_DESCRIPTOR *mSmramRanges;\r
-UINTN mSmramRangeCount;\r
-\r
//\r
// Interfaces for SMM Performance Protocol.\r
//\r
return EFI_SUCCESS;\r
}\r
\r
-/**\r
- This function check if the address is in SMRAM.\r
-\r
- @param Buffer the buffer address to be checked.\r
- @param Length the buffer length to be checked.\r
-\r
- @retval TRUE this address is in SMRAM.\r
- @retval FALSE this address is NOT in SMRAM.\r
-**/\r
-BOOLEAN\r
-IsAddressInSmram (\r
- IN EFI_PHYSICAL_ADDRESS Buffer,\r
- IN UINT64 Length\r
- )\r
-{\r
- UINTN Index;\r
-\r
- for (Index = 0; Index < mSmramRangeCount; Index ++) {\r
- if (((Buffer >= mSmramRanges[Index].CpuStart) && (Buffer < mSmramRanges[Index].CpuStart + mSmramRanges[Index].PhysicalSize)) ||\r
- ((mSmramRanges[Index].CpuStart >= Buffer) && (mSmramRanges[Index].CpuStart < Buffer + Length))) {\r
- return TRUE;\r
- }\r
- }\r
-\r
- return FALSE;\r
-}\r
-\r
-/**\r
- This function check if the address refered by Buffer and Length is valid.\r
-\r
- @param Buffer the buffer address to be checked.\r
- @param Length the buffer length to be checked.\r
-\r
- @retval TRUE this address is valid.\r
- @retval FALSE this address is NOT valid.\r
-**/\r
-BOOLEAN\r
-IsAddressValid (\r
- IN UINTN Buffer,\r
- IN UINTN Length\r
- )\r
-{\r
- if (Buffer > (MAX_ADDRESS - Length)) {\r
- //\r
- // Overflow happen\r
- //\r
- return FALSE;\r
- }\r
- if (IsAddressInSmram ((EFI_PHYSICAL_ADDRESS)Buffer, (UINT64)Length)) {\r
- return FALSE;\r
- }\r
- return TRUE;\r
-}\r
-\r
/**\r
Communication service SMI Handler entry.\r
\r
return EFI_SUCCESS;\r
}\r
\r
- if (!IsAddressValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
+ if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
DEBUG ((EFI_D_ERROR, "SmmPerformanceHandlerEx: SMM communcation data buffer in SMRAM or overflow!\n"));\r
return EFI_SUCCESS;\r
}\r
// Sanity check\r
//\r
DataSize = NumberOfEntries * sizeof(GAUGE_DATA_ENTRY_EX);\r
- if (!IsAddressValid ((UINTN)GaugeDataEx, DataSize)) {\r
+ if (!SmmIsBufferOutsideSmmValid ((UINTN)GaugeDataEx, DataSize)) {\r
DEBUG ((EFI_D_ERROR, "SmmPerformanceHandlerEx: SMM Performance Data buffer in SMRAM or overflow!\n"));\r
Status = EFI_ACCESS_DENIED;\r
break;\r
return EFI_SUCCESS;\r
}\r
\r
- if (!IsAddressValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
+ if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
DEBUG ((EFI_D_ERROR, "SmmPerformanceHandler: SMM communcation data buffer in SMRAM or overflow!\n"));\r
return EFI_SUCCESS;\r
}\r
// Sanity check\r
//\r
DataSize = NumberOfEntries * sizeof(GAUGE_DATA_ENTRY);\r
- if (!IsAddressValid ((UINTN)GaugeData, DataSize)) {\r
+ if (!SmmIsBufferOutsideSmmValid ((UINTN)GaugeData, DataSize)) {\r
DEBUG ((EFI_D_ERROR, "SmmPerformanceHandler: SMM Performance Data buffer in SMRAM or overflow!\n"));\r
Status = EFI_ACCESS_DENIED;\r
break;\r
{\r
EFI_STATUS Status;\r
EFI_HANDLE Handle;\r
- EFI_SMM_ACCESS2_PROTOCOL *SmmAccess;\r
- UINTN Size;\r
-\r
\r
//\r
// Initialize spin lock\r
mGaugeData = AllocateZeroPool (sizeof (GAUGE_DATA_HEADER) + (sizeof (GAUGE_DATA_ENTRY_EX) * mMaxGaugeRecords));\r
ASSERT (mGaugeData != NULL);\r
\r
- //\r
- // Get SMRAM information\r
- //\r
- Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **)&SmmAccess);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- Size = 0;\r
- Status = SmmAccess->GetCapabilities (SmmAccess, &Size, NULL);\r
- ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
-\r
- Status = gSmst->SmmAllocatePool (\r
- EfiRuntimeServicesData,\r
- Size,\r
- (VOID **)&mSmramRanges\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- Status = SmmAccess->GetCapabilities (SmmAccess, &Size, mSmramRanges);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- mSmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR);\r
-\r
//\r
// Install the protocol interfaces.\r
//\r
# This library is mainly used by SMM Core to start performance logging to ensure that\r
# SMM Performance and PerformanceEx Protocol are installed at the very beginning of SMM phase.\r
# \r
-# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2011 - 2015, 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
DebugLib\r
SynchronizationLib\r
SmmServicesTableLib\r
+ SmmMemLib\r
\r
[Protocols]\r
gEfiSmmBase2ProtocolGuid ## CONSUMES\r
This header file holds the prototypes of the SMM Performance and PerformanceEx Protocol published by this\r
library instance at its constructor.\r
\r
-Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2015, 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
#include <Library/UefiBootServicesTableLib.h>\r
#include <Library/MemoryAllocationLib.h>\r
#include <Library/SynchronizationLib.h>\r
+#include <Library/SmmMemLib.h>\r
\r
#include <Protocol/SmmBase2.h>\r
#include <Protocol/SmmAccess2.h>\r
# EFI/PI Reference Module Package for All Architectures\r
#\r
# (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>\r
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
#\r
# This program and the accompanying materials\r
# are licensed and made available under the terms and conditions of the BSD License\r
MemoryAllocationLib|MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationLib.inf\r
SmmServicesTableLib|MdeModulePkg/Library/PiSmmCoreSmmServicesTableLib/PiSmmCoreSmmServicesTableLib.inf\r
SmmCorePlatformHookLib|MdeModulePkg/Library/SmmCorePlatformHookLibNull/SmmCorePlatformHookLibNull.inf \r
+ SmmMemLib|MdePkg/Library/SmmMemLib/SmmMemLib.inf\r
\r
[LibraryClasses.common.DXE_SMM_DRIVER]\r
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAllocationLib.inf\r
SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableLib.inf\r
LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf\r
+ SmmMemLib|MdePkg/Library/SmmMemLib/SmmMemLib.inf\r
\r
[LibraryClasses.common.UEFI_DRIVER]\r
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
\r
FpdtSmiHandler() will receive untrusted input and do basic validation.\r
\r
- Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2011 - 2015, 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
#include <Library/MemoryAllocationLib.h>\r
#include <Library/UefiBootServicesTableLib.h>\r
#include <Library/SynchronizationLib.h>\r
+#include <Library/SmmMemLib.h>\r
\r
#define EXTENSION_RECORD_SIZE 0x1000\r
\r
UINT32 mBootRecordMaxSize = 0;\r
UINT8 *mBootRecordBuffer = NULL;\r
\r
-EFI_SMRAM_DESCRIPTOR *mSmramRanges;\r
-UINTN mSmramRangeCount;\r
SPIN_LOCK mSmmFpdtLock;\r
BOOLEAN mSmramIsOutOfResource = FALSE;\r
\r
return EFI_SUCCESS;\r
}\r
\r
-/**\r
- This function check if the address is in SMRAM.\r
-\r
- @param Buffer the buffer address to be checked.\r
- @param Length the buffer length to be checked.\r
-\r
- @retval TRUE this address is in SMRAM.\r
- @retval FALSE this address is NOT in SMRAM.\r
-**/\r
-BOOLEAN\r
-InternalIsAddressInSmram (\r
- IN EFI_PHYSICAL_ADDRESS Buffer,\r
- IN UINT64 Length\r
- )\r
-{\r
- UINTN Index;\r
-\r
- for (Index = 0; Index < mSmramRangeCount; Index ++) {\r
- if (((Buffer >= mSmramRanges[Index].CpuStart) && (Buffer < mSmramRanges[Index].CpuStart + mSmramRanges[Index].PhysicalSize)) ||\r
- ((mSmramRanges[Index].CpuStart >= Buffer) && (mSmramRanges[Index].CpuStart < Buffer + Length))) {\r
- return TRUE;\r
- }\r
- }\r
-\r
- return FALSE;\r
-}\r
-\r
-/**\r
- This function check if the address refered by Buffer and Length is valid.\r
-\r
- @param Buffer the buffer address to be checked.\r
- @param Length the buffer length to be checked.\r
-\r
- @retval TRUE this address is valid.\r
- @retval FALSE this address is NOT valid.\r
-**/\r
-BOOLEAN\r
-InternalIsAddressValid (\r
- IN UINTN Buffer,\r
- IN UINTN Length\r
- )\r
-{\r
- if (Buffer > (MAX_ADDRESS - Length)) {\r
- //\r
- // Overflow happen\r
- //\r
- return FALSE;\r
- }\r
- if (InternalIsAddressInSmram ((EFI_PHYSICAL_ADDRESS)Buffer, (UINT64)Length)) {\r
- return FALSE;\r
- }\r
- return TRUE;\r
-}\r
-\r
/**\r
Communication service SMI Handler entry.\r
\r
return EFI_SUCCESS;\r
}\r
\r
- if (!InternalIsAddressValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
+ if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
DEBUG ((EFI_D_ERROR, "FpdtSmiHandler: SMM communication data buffer in SMRAM or overflow!\n"));\r
return EFI_SUCCESS;\r
}\r
// Sanity check\r
//\r
SmmCommData->BootRecordSize = mBootRecordSize;\r
- if (!InternalIsAddressValid ((UINTN)BootRecordData, mBootRecordSize)) {\r
+ if (!SmmIsBufferOutsideSmmValid ((UINTN)BootRecordData, mBootRecordSize)) {\r
DEBUG ((EFI_D_ERROR, "FpdtSmiHandler: SMM Data buffer in SMRAM or overflow!\n"));\r
Status = EFI_ACCESS_DENIED;\r
break;\r
{\r
EFI_STATUS Status;\r
EFI_HANDLE Handle;\r
- EFI_SMM_ACCESS2_PROTOCOL *SmmAccess;\r
- UINTN Size;\r
\r
//\r
// Initialize spin lock\r
Status = mRscHandlerProtocol->Register (FpdtStatusCodeListenerSmm);\r
ASSERT_EFI_ERROR (Status);\r
\r
- //\r
- // Get SMRAM information\r
- //\r
- Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **)&SmmAccess);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- Size = 0;\r
- Status = SmmAccess->GetCapabilities (SmmAccess, &Size, NULL);\r
- ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
-\r
- Status = gSmst->SmmAllocatePool (\r
- EfiRuntimeServicesData,\r
- Size,\r
- (VOID **)&mSmramRanges\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- Status = SmmAccess->GetCapabilities (SmmAccess, &Size, mSmramRanges);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- mSmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR);\r
-\r
//\r
// Register SMI handler.\r
//\r
# This module registers report status code listener to collect performance data\r
# for SMM boot performance records and S3 Suspend Performance Record.\r
#\r
-# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2011 - 2015, 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
MemoryAllocationLib\r
UefiBootServicesTableLib\r
SynchronizationLib\r
+ SmmMemLib\r
\r
[Protocols]\r
gEfiSmmRscHandlerProtocolGuid ## CONSUMES\r
Caution: This module requires additional review when modified.\r
This driver need to make sure the CommBuffer is not in the SMRAM range. \r
\r
-Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2015, 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
\r
#include <PiSmm.h>\r
#include <Library/SmmServicesTableLib.h>\r
+#include <Library/SmmMemLib.h>\r
#include <Protocol/SmmSwapAddressRange.h>\r
#include "FaultTolerantWrite.h"\r
#include "FaultTolerantWriteSmmCommon.h"\r
\r
EFI_EVENT mFvbRegistration = NULL;\r
EFI_FTW_DEVICE *mFtwDevice = NULL;\r
-EFI_SMRAM_DESCRIPTOR *mSmramRanges;\r
-UINTN mSmramRangeCount;\r
\r
///\r
/// The flag to indicate whether the platform has left the DXE phase of execution.\r
///\r
BOOLEAN mEndOfDxe = FALSE;\r
\r
-/**\r
- This function check if the address is in SMRAM.\r
-\r
- @param Buffer the buffer address to be checked.\r
- @param Length the buffer length to be checked.\r
-\r
- @retval TRUE this address is in SMRAM.\r
- @retval FALSE this address is NOT in SMRAM.\r
-**/\r
-BOOLEAN\r
-InternalIsAddressInSmram (\r
- IN EFI_PHYSICAL_ADDRESS Buffer,\r
- IN UINT64 Length\r
- )\r
-{\r
- UINTN Index;\r
-\r
- for (Index = 0; Index < mSmramRangeCount; Index ++) {\r
- if (((Buffer >= mSmramRanges[Index].CpuStart) && (Buffer < mSmramRanges[Index].CpuStart + mSmramRanges[Index].PhysicalSize)) ||\r
- ((mSmramRanges[Index].CpuStart >= Buffer) && (mSmramRanges[Index].CpuStart < Buffer + Length))) {\r
- return TRUE;\r
- }\r
- }\r
-\r
- return FALSE;\r
-}\r
-\r
-/**\r
- This function check if the address refered by Buffer and Length is valid.\r
-\r
- @param Buffer the buffer address to be checked.\r
- @param Length the buffer length to be checked.\r
-\r
- @retval TRUE this address is valid.\r
- @retval FALSE this address is NOT valid.\r
-**/\r
-BOOLEAN\r
-InternalIsAddressValid (\r
- IN UINTN Buffer,\r
- IN UINTN Length\r
- )\r
-{\r
- if (Buffer > (MAX_ADDRESS - Length)) {\r
- //\r
- // Overflow happen\r
- //\r
- return FALSE;\r
- }\r
- if (InternalIsAddressInSmram ((EFI_PHYSICAL_ADDRESS)Buffer, (UINT64)Length)) {\r
- return FALSE;\r
- }\r
- return TRUE;\r
-}\r
-\r
/**\r
Retrive the SMM FVB protocol interface by HANDLE.\r
\r
}\r
CommBufferPayloadSize = TempCommBufferSize - SMM_FTW_COMMUNICATE_HEADER_SIZE;\r
\r
- if (!InternalIsAddressValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
+ if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
DEBUG ((EFI_D_ERROR, "SmmFtwHandler: SMM communication buffer in SMRAM or overflow!\n"));\r
return EFI_SUCCESS;\r
}\r
)\r
{\r
EFI_STATUS Status;\r
- EFI_SMM_ACCESS2_PROTOCOL *SmmAccess;\r
- UINTN Size;\r
VOID *SmmEndOfDxeRegistration;\r
\r
//\r
return Status;\r
}\r
\r
- //\r
- // Get SMRAM information\r
- //\r
- Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **)&SmmAccess);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- Size = 0;\r
- Status = SmmAccess->GetCapabilities (SmmAccess, &Size, NULL);\r
- ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
-\r
- Status = gSmst->SmmAllocatePool (\r
- EfiRuntimeServicesData,\r
- Size,\r
- (VOID **)&mSmramRanges\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- Status = SmmAccess->GetCapabilities (SmmAccess, &Size, mSmramRanges);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- mSmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR);\r
-\r
//\r
// Register EFI_SMM_END_OF_DXE_PROTOCOL_GUID notify function.\r
//\r
# depends on the full functionality SMM FVB protocol that support read, write/erase \r
# flash access.\r
#\r
-# Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
#\r
# This program and the accompanying materials\r
# are licensed and made available under the terms and conditions of the BSD License\r
UefiLib\r
PcdLib\r
ReportStatusCodeLib\r
+ SmmMemLib\r
\r
[Guids]\r
#\r
SmmLockBoxHandler(), SmmLockBoxRestore(), SmmLockBoxUpdate(), SmmLockBoxSave()\r
will receive untrusted input and do basic validation.\r
\r
-Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions\r
#include <Library/BaseLib.h>\r
#include <Library/BaseMemoryLib.h>\r
#include <Library/DebugLib.h>\r
+#include <Library/SmmMemLib.h>\r
#include <Library/LockBoxLib.h>\r
+\r
#include <Protocol/SmmReadyToLock.h>\r
#include <Protocol/SmmCommunication.h>\r
#include <Protocol/SmmAccess2.h>\r
\r
BOOLEAN mLocked = FALSE;\r
\r
-EFI_SMRAM_DESCRIPTOR *mSmramRanges;\r
-UINTN mSmramRangeCount;\r
-\r
-/**\r
- This function check if the address is in SMRAM.\r
-\r
- @param Buffer the buffer address to be checked.\r
- @param Length the buffer length to be checked.\r
-\r
- @retval TRUE this address is in SMRAM.\r
- @retval FALSE this address is NOT in SMRAM.\r
-**/\r
-BOOLEAN\r
-IsAddressInSmram (\r
- IN EFI_PHYSICAL_ADDRESS Buffer,\r
- IN UINT64 Length\r
- )\r
-{\r
- UINTN Index;\r
-\r
- for (Index = 0; Index < mSmramRangeCount; Index ++) {\r
- if (((Buffer >= mSmramRanges[Index].CpuStart) && (Buffer < mSmramRanges[Index].CpuStart + mSmramRanges[Index].PhysicalSize)) ||\r
- ((mSmramRanges[Index].CpuStart >= Buffer) && (mSmramRanges[Index].CpuStart < Buffer + Length))) {\r
- return TRUE;\r
- }\r
- }\r
-\r
- return FALSE;\r
-}\r
-\r
-/**\r
- This function check if the address refered by Buffer and Length is valid.\r
-\r
- @param Buffer the buffer address to be checked.\r
- @param Length the buffer length to be checked.\r
-\r
- @retval TRUE this address is valid.\r
- @retval FALSE this address is NOT valid.\r
-**/\r
-BOOLEAN\r
-IsAddressValid (\r
- IN UINTN Buffer,\r
- IN UINTN Length\r
- )\r
-{\r
- if (Buffer > (MAX_ADDRESS - Length)) {\r
- //\r
- // Overflow happen\r
- //\r
- return FALSE;\r
- }\r
- if (IsAddressInSmram ((EFI_PHYSICAL_ADDRESS)Buffer, (UINT64)Length)) {\r
- return FALSE;\r
- }\r
- return TRUE;\r
-}\r
-\r
/**\r
Dispatch function for SMM lock box save.\r
\r
//\r
// Sanity check\r
//\r
- if (!IsAddressValid ((UINTN)TempLockBoxParameterSave.Buffer, (UINTN)TempLockBoxParameterSave.Length)) {\r
+ if (!SmmIsBufferOutsideSmmValid ((UINTN)TempLockBoxParameterSave.Buffer, (UINTN)TempLockBoxParameterSave.Length)) {\r
DEBUG ((EFI_D_ERROR, "SmmLockBox Save address in SMRAM or buffer overflow!\n"));\r
LockBoxParameterSave->Header.ReturnStatus = (UINT64)EFI_ACCESS_DENIED;\r
return ;\r
//\r
// Sanity check\r
//\r
- if (!IsAddressValid ((UINTN)TempLockBoxParameterUpdate.Buffer, (UINTN)TempLockBoxParameterUpdate.Length)) {\r
+ if (!SmmIsBufferOutsideSmmValid ((UINTN)TempLockBoxParameterUpdate.Buffer, (UINTN)TempLockBoxParameterUpdate.Length)) {\r
DEBUG ((EFI_D_ERROR, "SmmLockBox Update address in SMRAM or buffer overflow!\n"));\r
LockBoxParameterUpdate->Header.ReturnStatus = (UINT64)EFI_ACCESS_DENIED;\r
return ;\r
//\r
// Sanity check\r
//\r
- if (!IsAddressValid ((UINTN)TempLockBoxParameterRestore.Buffer, (UINTN)TempLockBoxParameterRestore.Length)) {\r
+ if (!SmmIsBufferOutsideSmmValid ((UINTN)TempLockBoxParameterRestore.Buffer, (UINTN)TempLockBoxParameterRestore.Length)) {\r
DEBUG ((EFI_D_ERROR, "SmmLockBox Restore address in SMRAM or buffer overflow!\n"));\r
LockBoxParameterRestore->Header.ReturnStatus = (UINT64)EFI_ACCESS_DENIED;\r
return ;\r
DEBUG ((EFI_D_ERROR, "SmmLockBox Command Buffer Size invalid!\n"));\r
return EFI_SUCCESS;\r
}\r
- if (!IsAddressValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
+ if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
DEBUG ((EFI_D_ERROR, "SmmLockBox Command Buffer in SMRAM or overflow!\n"));\r
return EFI_SUCCESS;\r
}\r
EFI_STATUS Status;\r
EFI_HANDLE DispatchHandle;\r
VOID *Registration;\r
- EFI_SMM_ACCESS2_PROTOCOL *SmmAccess;\r
- UINTN Size;\r
-\r
- //\r
- // Get SMRAM information\r
- //\r
- Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **)&SmmAccess);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- Size = 0;\r
- Status = SmmAccess->GetCapabilities (SmmAccess, &Size, NULL);\r
- ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
-\r
- Status = gSmst->SmmAllocatePool (\r
- EfiRuntimeServicesData,\r
- Size,\r
- (VOID **)&mSmramRanges\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- Status = SmmAccess->GetCapabilities (SmmAccess, &Size, mSmramRanges);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- mSmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR);\r
\r
//\r
// Register LockBox communication handler\r
# This external input must be validated carefully to avoid security issue like\r
# buffer overflow, integer overflow.\r
#\r
-# Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
#\r
# This program and the accompanying materials\r
# are licensed and made available under the terms and conditions\r
BaseMemoryLib\r
DebugLib\r
LockBoxLib\r
+ SmmMemLib\r
\r
[Guids]\r
gEfiSmmLockBoxCommunicationGuid ## PRODUCES ## GUID # SmiHandlerRegister\r
#include <Protocol/SmmVarCheck.h>\r
\r
#include <Library/SmmServicesTableLib.h>\r
+#include <Library/SmmMemLib.h>\r
\r
#include <Guid/VariableFormat.h>\r
#include <Guid/SmmVariableCommon.h>\r
#include "Variable.h"\r
\r
-EFI_SMRAM_DESCRIPTOR *mSmramRanges;\r
-UINTN mSmramRangeCount;\r
-\r
extern VARIABLE_INFO_ENTRY *gVariableInfo;\r
EFI_HANDLE mSmmVariableHandle = NULL;\r
EFI_HANDLE mVariableHandle = NULL;\r
return mAtRuntime;\r
}\r
\r
-/**\r
- This function check if the address is in SMRAM.\r
-\r
- @param Buffer the buffer address to be checked.\r
- @param Length the buffer length to be checked.\r
-\r
- @retval TRUE this address is in SMRAM.\r
- @retval FALSE this address is NOT in SMRAM.\r
-**/\r
-BOOLEAN\r
-InternalIsAddressInSmram (\r
- IN EFI_PHYSICAL_ADDRESS Buffer,\r
- IN UINT64 Length\r
- )\r
-{\r
- UINTN Index;\r
-\r
- for (Index = 0; Index < mSmramRangeCount; Index ++) {\r
- if (((Buffer >= mSmramRanges[Index].CpuStart) && (Buffer < mSmramRanges[Index].CpuStart + mSmramRanges[Index].PhysicalSize)) ||\r
- ((mSmramRanges[Index].CpuStart >= Buffer) && (mSmramRanges[Index].CpuStart < Buffer + Length))) {\r
- return TRUE;\r
- }\r
- }\r
-\r
- return FALSE;\r
-}\r
-\r
-/**\r
- This function check if the address refered by Buffer and Length is valid.\r
-\r
- @param Buffer the buffer address to be checked.\r
- @param Length the buffer length to be checked.\r
-\r
- @retval TRUE this address is valid.\r
- @retval FALSE this address is NOT valid.\r
-**/\r
-BOOLEAN\r
-InternalIsAddressValid (\r
- IN UINTN Buffer,\r
- IN UINTN Length\r
- )\r
-{\r
- if (Buffer > (MAX_ADDRESS - Length)) {\r
- //\r
- // Overflow happen\r
- //\r
- return FALSE;\r
- }\r
- if (InternalIsAddressInSmram ((EFI_PHYSICAL_ADDRESS)Buffer, (UINT64)Length)) {\r
- return FALSE;\r
- }\r
- return TRUE;\r
-}\r
-\r
/**\r
Initializes a basic mutual exclusion lock.\r
\r
return EFI_SUCCESS;\r
}\r
\r
- if (!InternalIsAddressValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
+ if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {\r
DEBUG ((EFI_D_ERROR, "SmmVariableHandler: SMM communication buffer in SMRAM or overflow!\n"));\r
return EFI_SUCCESS;\r
}\r
// It is covered by previous CommBuffer check \r
//\r
\r
- if (InternalIsAddressInSmram ((EFI_PHYSICAL_ADDRESS)(UINTN)CommBufferSize, sizeof(UINTN))) {\r
+ if (!SmmIsBufferOutsideSmmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)CommBufferSize, sizeof(UINTN))) {\r
DEBUG ((EFI_D_ERROR, "GetStatistics: SMM communication buffer in SMRAM!\n"));\r
Status = EFI_ACCESS_DENIED;\r
goto EXIT;\r
EFI_STATUS Status;\r
EFI_HANDLE VariableHandle;\r
VOID *SmmFtwRegistration;\r
- EFI_SMM_ACCESS2_PROTOCOL *SmmAccess;\r
- UINTN Size;\r
VOID *SmmEndOfDxeRegistration;\r
\r
//\r
);\r
ASSERT_EFI_ERROR (Status);\r
\r
- //\r
- // Get SMRAM information\r
- //\r
- Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **)&SmmAccess);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- Size = 0;\r
- Status = SmmAccess->GetCapabilities (SmmAccess, &Size, NULL);\r
- ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
-\r
- Status = gSmst->SmmAllocatePool (\r
- EfiRuntimeServicesData,\r
- Size,\r
- (VOID **)&mSmramRanges\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- Status = SmmAccess->GetCapabilities (SmmAccess, &Size, mSmramRanges);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- mSmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR);\r
-\r
mVariableBufferPayloadSize = MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 (PcdMaxHardwareErrorVariableSize)) +\r
OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) - sizeof (VARIABLE_HEADER);\r
\r
HobLib\r
PcdLib\r
DevicePathLib\r
+ SmmMemLib\r
\r
[Protocols]\r
gEfiSmmFirmwareVolumeBlockProtocolGuid ## CONSUMES\r