From 468b3d9589e5dfb18008fcd27ade67584b95ca83 Mon Sep 17 00:00:00 2001 From: Dun Tan Date: Fri, 22 Nov 2024 11:17:35 +0800 Subject: [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm:Check resource HOB range before mapping 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 --- UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapStandaloneMm.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapStandaloneMm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapStandaloneMm.c index dba7db0d0099..6edbf9dfcf61 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapStandaloneMm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapStandaloneMm.c @@ -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. @@ -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.