]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmVirtPkg/HighMemDxe/HighMemDxe.c
ArmVirtPkg/HighMemDxe: preserve non-exec permissions on newly added regions
[mirror_edk2.git] / ArmVirtPkg / HighMemDxe / HighMemDxe.c
index 22f738279b202e3256e08e8cbd7094fc71767f86..f70978f6414fc80c0325feb7afa42339ae4699f6 100644 (file)
@@ -37,6 +37,7 @@ InitializeHighMemDxe (
   UINTN                 AddressCells, SizeCells;\r
   UINT64                CurBase;\r
   UINT64                CurSize;\r
+  UINT64                Attributes;\r
 \r
   Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,\r
                   (VOID **)&FdtClient);\r
@@ -77,8 +78,21 @@ InitializeHighMemDxe (
           continue;\r
         }\r
 \r
-        Status = gDS->SetMemorySpaceAttributes (CurBase, CurSize,\r
-                        EFI_MEMORY_WB);\r
+        //\r
+        // Take care not to strip any permission attributes that will have been\r
+        // set by DxeCore on the region we just added if a strict permission\r
+        // policy is in effect for EfiConventionalMemory regions.\r
+        // Unfortunately, we cannot interrogate the GCD memory space map for\r
+        // those permissions, since they are not recorded there (for historical\r
+        // reasons), so check the policy directly.\r
+        //\r
+        Attributes = EFI_MEMORY_WB;\r
+        if ((PcdGet64 (PcdDxeNxMemoryProtectionPolicy) &\r
+             (1U << (UINT32)EfiConventionalMemory)) != 0) {\r
+          Attributes |= EFI_MEMORY_XP;\r
+        }\r
+\r
+        Status = gDS->SetMemorySpaceAttributes (CurBase, CurSize, Attributes);\r
 \r
         if (EFI_ERROR (Status)) {\r
           DEBUG ((EFI_D_ERROR,\r