\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