Skip to content

Commit

Permalink
UefiCpuPkg/PiSmmCpuDxeSmm:Check resource HOB range before mapping
Browse files Browse the repository at this point in the history
This commit is to check if the resource HOB range does not
exceed the max supported physical address.
The function BuildMemoryMapFromResDescHobs is to build Memory
Region from resource HOBs. Then the memory maps will be used
during creating or modifying SMM page table. If the resource
HOB range exceeds the max supported physical address, then
subsequent calling of PageTableMap() will fail.

Signed-off-by: Dun Tan <[email protected]>
  • Loading branch information
td36 authored and mergify[bot] committed Nov 25, 2024
1 parent 065df32 commit 468b3d9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapStandaloneMm.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,14 @@ BuildMemoryMapFromResDescHobs (
EFI_PEI_HOB_POINTERS Hob;
UINTN Count;
UINTN Index;
EFI_PHYSICAL_ADDRESS MaxPhysicalAddress;
EFI_PHYSICAL_ADDRESS ResourceHobEnd;

ASSERT (MemoryRegion != NULL && MemoryRegionCount != NULL);

*MemoryRegion = NULL;
*MemoryRegionCount = 0;
MaxPhysicalAddress = LShiftU64 (1, mPhysicalAddressBits);

//
// Get the count.
Expand All @@ -138,6 +141,13 @@ BuildMemoryMapFromResDescHobs (
Hob.Raw = GetFirstHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR);
while (Hob.Raw != NULL) {
if ((Hob.ResourceDescriptor->ResourceAttribute & MM_RESOURCE_ATTRIBUTE_LOGGING) == 0) {
ResourceHobEnd = Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength;

ASSERT (ResourceHobEnd <= MaxPhysicalAddress);
if (ResourceHobEnd > MaxPhysicalAddress) {
CpuDeadLoop ();
}

//
// Resource HOBs describe all accessible non-smram regions.
// Logging attribute range is treated as not present. Not-present ranges are not included in this memory map.
Expand Down

0 comments on commit 468b3d9

Please sign in to comment.