} while (Status == EFI_BUFFER_TOO_SMALL);\r
ASSERT_EFI_ERROR (Status);\r
\r
- DEBUG((DEBUG_ERROR, "%a: applying strict permissions to active memory regions\n",\r
- __FUNCTION__));\r
+ DEBUG ((\r
+ DEBUG_INFO,\r
+ "%a: applying strict permissions to active memory regions\n",\r
+ __FUNCTION__\r
+ ));\r
\r
MergeMemoryMapForProtectionPolicy (MemoryMap, &MemoryMapSize, DescriptorSize);\r
\r
\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
// accessible, but have not been added to the UEFI memory map (yet).\r
//\r
if (GetPermissionAttributeForMemoryType (EfiConventionalMemory) != 0) {\r
- DEBUG((DEBUG_ERROR,\r
+ DEBUG ((\r
+ DEBUG_INFO,\r
"%a: applying strict permissions to inactive memory regions\n",\r
- __FUNCTION__));\r
+ __FUNCTION__\r
+ ));\r
\r
CoreAcquireGcdMemoryLock ();\r
\r
// - code regions should have no EFI_MEMORY_XP attribute\r
// - EfiConventionalMemory and EfiBootServicesData should use the\r
// same attribute\r
- // - heap guard should not be enabled for the same type of memory
//\r
ASSERT ((GetPermissionAttributeForMemoryType (EfiBootServicesCode) & EFI_MEMORY_XP) == 0);\r
ASSERT ((GetPermissionAttributeForMemoryType (EfiRuntimeServicesCode) & EFI_MEMORY_XP) == 0);\r
ASSERT ((GetPermissionAttributeForMemoryType (EfiLoaderCode) & EFI_MEMORY_XP) == 0);\r
ASSERT (GetPermissionAttributeForMemoryType (EfiBootServicesData) ==\r
GetPermissionAttributeForMemoryType (EfiConventionalMemory));\r
- ASSERT ((PcdGet64 (PcdDxeNxMemoryProtectionPolicy) & PcdGet64 (PcdHeapGuardPoolType)) == 0);
- ASSERT ((PcdGet64 (PcdDxeNxMemoryProtectionPolicy) & PcdGet64 (PcdHeapGuardPageType)) == 0);
\r
if (mImageProtectionPolicy != 0 || PcdGet64 (PcdDxeNxMemoryProtectionPolicy) != 0) {\r
Status = CoreCreateEvent (\r