]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/Core: fix ineffective guard page issue
authorJian J Wang <jian.j.wang@intel.com>
Wed, 7 Nov 2018 00:48:09 +0000 (08:48 +0800)
committerJian J Wang <jian.j.wang@intel.com>
Wed, 7 Nov 2018 15:08:27 +0000 (23:08 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1295

This issue originates from following patch which allows to enable
paging if PcdImageProtectionPolicy and PcdDxeNxMemoryProtectionPolicy
(in addition to PcdSetNxForStack) are set to enable related features.

  5267926134d17e86672b84fd57b438f05ffa68e1

Due to above change, PcdImageProtectionPolicy will be set to 0 by
default in many platforms, which, in turn, cause following code in
MdeModulePkg\Core\Dxe\Misc\MemoryProtection.c fail the creation of
notify event of CpuArchProtocol.

1138:  if (mImageProtectionPolicy != 0 ||
           PcdGet64 (PcdDxeNxMemoryProtectionPolicy) != 0) {
1139:  Status = CoreCreateEvent (
...
1142:             MemoryProtectionCpuArchProtocolNotify,
...
1145:             );

Then following call flow won't be done and Guard pages will not be
set as not-present in SetAllGuardPages() eventually.

   MemoryProtectionCpuArchProtocolNotify()
=> HeapGuardCpuArchProtocolNotify()
=> SetAllGuardPages()

The solution is removing the if(...) statement so that the notify
event will always be created and registered. This won't cause
unnecessary code execution because, in the notify event handler,
the related PCDs like

    PcdImageProtectionPolicy and
    PcdDxeNxMemoryProtectionPolicy

will be checked again before doing related jobs.

Cc: Star Zeng <star.zeng@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c

index 8a93c5362a3f33fef72c406bad3f215efbbffe11..c43e0d08ae7caa72695dc43fdf356c86a2d6fbb7 100644 (file)
@@ -1136,26 +1136,24 @@ CoreInitializeMemoryProtection (
   ASSERT (GetPermissionAttributeForMemoryType (EfiBootServicesData) ==\r
           GetPermissionAttributeForMemoryType (EfiConventionalMemory));\r
 \r
-  if (mImageProtectionPolicy != 0 || PcdGet64 (PcdDxeNxMemoryProtectionPolicy) != 0) {\r
-    Status = CoreCreateEvent (\r
-               EVT_NOTIFY_SIGNAL,\r
-               TPL_CALLBACK,\r
-               MemoryProtectionCpuArchProtocolNotify,\r
-               NULL,\r
-               &Event\r
-               );\r
-    ASSERT_EFI_ERROR(Status);\r
+  Status = CoreCreateEvent (\r
+             EVT_NOTIFY_SIGNAL,\r
+             TPL_CALLBACK,\r
+             MemoryProtectionCpuArchProtocolNotify,\r
+             NULL,\r
+             &Event\r
+             );\r
+  ASSERT_EFI_ERROR(Status);\r
 \r
-    //\r
-    // Register for protocol notifactions on this event\r
-    //\r
-    Status = CoreRegisterProtocolNotify (\r
-               &gEfiCpuArchProtocolGuid,\r
-               Event,\r
-               &Registration\r
-               );\r
-    ASSERT_EFI_ERROR(Status);\r
-  }\r
+  //\r
+  // Register for protocol notifactions on this event\r
+  //\r
+  Status = CoreRegisterProtocolNotify (\r
+             &gEfiCpuArchProtocolGuid,\r
+             Event,\r
+             &Registration\r
+             );\r
+  ASSERT_EFI_ERROR(Status);\r
 \r
   //\r
   // Register a callback to disable NULL pointer detection at EndOfDxe\r