summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDun Tan <dun.tan@intel.com>2024-11-22 11:17:35 +0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2024-11-25 18:39:40 +0000
commit468b3d9589e5dfb18008fcd27ade67584b95ca83 (patch)
tree92cb64103dd6ebd03affd119c1619ea911321459
parent065df32de381243588855b03ae49344b6b07a061 (diff)
downloadedk2-468b3d9589e5dfb18008fcd27ade67584b95ca83.tar.gz
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 <dun.tan@intel.com>
-rw-r--r--UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapStandaloneMm.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapStandaloneMm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapStandaloneMm.c
index dba7db0d00..6edbf9dfcf 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.