]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c
ArmPkg/ArmMmuLib AARCH64: fix out of bounds access
[mirror_edk2.git] / ArmPkg / Library / ArmMmuLib / AArch64 / ArmMmuLibCore.c
index df170d20a2c259fd6f1b2cb0a54a7337b07a2785..d66df3e17a02a17c71b4ff947963de3f584320a6 100644 (file)
@@ -35,6 +35,10 @@ ArmMemoryAttributeToPageAttribute (
   )\r
 {\r
   switch (Attributes) {\r
+  case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK_NONSHAREABLE:\r
+  case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK_NONSHAREABLE:\r
+    return TT_ATTR_INDX_MEMORY_WRITE_BACK;\r
+\r
   case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK:\r
   case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK:\r
     return TT_ATTR_INDX_MEMORY_WRITE_BACK | TT_SH_INNER_SHAREABLE;\r
@@ -378,7 +382,7 @@ UpdateRegionMapping (
 \r
       // Break the inner loop when next block is a table\r
       // Rerun GetBlockEntryListFromAddress to avoid page table memory leak\r
-      if (TableLevel != 3 &&\r
+      if (TableLevel != 3 && BlockEntry <= LastBlockEntry &&\r
           (*BlockEntry & TT_TYPE_MASK) == TT_TYPE_TABLE_ENTRY) {\r
             break;\r
       }\r
@@ -447,11 +451,10 @@ GcdAttributeToPageAttribute (
 }\r
 \r
 EFI_STATUS\r
-SetMemoryAttributes (\r
+ArmSetMemoryAttributes (\r
   IN EFI_PHYSICAL_ADDRESS      BaseAddress,\r
   IN UINT64                    Length,\r
-  IN UINT64                    Attributes,\r
-  IN EFI_PHYSICAL_ADDRESS      VirtualMask\r
+  IN UINT64                    Attributes\r
   )\r
 {\r
   EFI_STATUS                   Status;\r
@@ -601,8 +604,15 @@ ArmConfigureMmu (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  // Cover the entire GCD memory space\r
-  MaxAddress = (1UL << PcdGet8 (PcdPrePiCpuMemorySize)) - 1;\r
+  //\r
+  // Limit the virtual address space to what we can actually use: UEFI\r
+  // mandates a 1:1 mapping, so no point in making the virtual address\r
+  // space larger than the physical address space. We also have to take\r
+  // into account the architectural limitations that result from UEFI's\r
+  // use of 4 KB pages.\r
+  //\r
+  MaxAddress = MIN (LShiftU64 (1ULL, ArmGetPhysicalAddressBits ()) - 1,\r
+                    MAX_ALLOC_ADDRESS);\r
 \r
   // Lookup the Table Level to get the information\r
   LookupAddresstoRootTable (MaxAddress, &T0SZ, &RootTableEntryCount);\r