]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/Core: Refine handling NULL detection in NX setting
authorHao Wu <hao.a.wu@intel.com>
Tue, 6 Mar 2018 10:36:37 +0000 (18:36 +0800)
committerHao Wu <hao.a.wu@intel.com>
Wed, 7 Mar 2018 12:56:42 +0000 (20:56 +0800)
The commit rewrites the logic in function
InitializeDxeNxMemoryProtectionPolicy() for handling the first page
(page 0) when NULL pointer detection feature is enabled.

Instead of skip setting the page 0, the codes will now override the
attribute setting of page 0 by adding the 'EFI_MEMORY_RP' attribute.

The purpose is to make it easy for other special handling of pages
(e.g. the first page of the stack when stack guard feature is enabled).

Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c

index 455ed35f9a36541272ea21effd7d13f23f5caf84..a2ea445eefa6046084d1f1bbed2a9ee757c9f8ac 100644 (file)
@@ -19,7 +19,7 @@
 \r
   Once the image is unloaded, the protection is removed automatically.\r
 \r
-Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -846,23 +846,23 @@ 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
+\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
+        // Add EFI_MEMORY_RP attribute for page 0 if NULL pointer detection is\r
+        // enabled.\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
+          0,\r
+          EFI_PAGES_TO_SIZE (1),\r
+          EFI_MEMORY_RP | Attributes);\r
       }\r
     }\r
     MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);\r