]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c
MdeModulePkg/Core: fix feature conflict between NX and NULL detection
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Misc / MemoryProtection.c
index 862593f562ca7defed3e1e41ad732443037b4458..a4705bc7ce343f002fb933829e9cecfaa3ec7987 100644 (file)
@@ -845,10 +845,24 @@ InitializeDxeNxMemoryProtectionPolicy (
 \r
     Attributes = GetPermissionAttributeForMemoryType (MemoryMapEntry->Type);\r
     if (Attributes != 0) {\r
-      SetUefiImageMemoryAttributes (\r
-        MemoryMapEntry->PhysicalStart,\r
-        LShiftU64 (MemoryMapEntry->NumberOfPages, EFI_PAGE_SHIFT),\r
-        Attributes);\r
+      if (MemoryMapEntry->PhysicalStart == 0 &&\r
+          PcdGet8 (PcdNullPointerDetectionPropertyMask) != 0) {\r
+\r
+        ASSERT (MemoryMapEntry->NumberOfPages > 0);\r
+        //\r
+        // Skip page 0 if NULL pointer detection is enabled to avoid attributes\r
+        // overwritten.\r
+        //\r
+        SetUefiImageMemoryAttributes (\r
+          MemoryMapEntry->PhysicalStart + EFI_PAGE_SIZE,\r
+          LShiftU64 (MemoryMapEntry->NumberOfPages - 1, EFI_PAGE_SHIFT),\r
+          Attributes);\r
+      } else {\r
+        SetUefiImageMemoryAttributes (\r
+          MemoryMapEntry->PhysicalStart,\r
+          LShiftU64 (MemoryMapEntry->NumberOfPages, EFI_PAGE_SHIFT),\r
+          Attributes);\r
+      }\r
     }\r
     MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);\r
   }\r