]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/DxeCore: add sanity check for SetMemoryAttributes
authorJian J Wang <jian.j.wang@intel.com>
Wed, 11 Apr 2018 08:35:05 +0000 (16:35 +0800)
committerStar Zeng <star.zeng@intel.com>
Fri, 13 Apr 2018 05:04:59 +0000 (13:04 +0800)
Heap Guard feature needs enough memory and paging to work. Otherwise
calling SetMemoryAttributes to change page attribute will fail. This
patch add necessary check of result of calling SetMemoryAttributes.
This can help users to debug their problem in enabling this feature.

Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
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/Mem/HeapGuard.c

index fd6aeee8da9d70c5e7523d41064cdc2b85e5c6df..9d765c98f6ab3b5017d47bc8694a48671ad174f7 100644 (file)
@@ -580,6 +580,8 @@ SetGuardPage (
   IN  EFI_PHYSICAL_ADDRESS      BaseAddress\r
   )\r
 {\r
+  EFI_STATUS      Status;\r
+\r
   if (gCpu == NULL) {\r
     return;\r
   }\r
@@ -593,7 +595,8 @@ SetGuardPage (
   // Note: This might overwrite other attributes needed by other features,\r
   // such as NX memory protection.\r
   //\r
-  gCpu->SetMemoryAttributes (gCpu, BaseAddress, EFI_PAGE_SIZE, EFI_MEMORY_RP);\r
+  Status = gCpu->SetMemoryAttributes (gCpu, BaseAddress, EFI_PAGE_SIZE, EFI_MEMORY_RP);\r
+  ASSERT_EFI_ERROR (Status);\r
   mOnGuarding = FALSE;\r
 }\r
 \r
@@ -613,6 +616,7 @@ UnsetGuardPage (
   )\r
 {\r
   UINT64          Attributes;\r
+  EFI_STATUS      Status;\r
 \r
   if (gCpu == NULL) {\r
     return;\r
@@ -638,7 +642,8 @@ UnsetGuardPage (
   // such as memory protection (NX). Please make sure they are not enabled\r
   // at the same time.\r
   //\r
-  gCpu->SetMemoryAttributes (gCpu, BaseAddress, EFI_PAGE_SIZE, Attributes);\r
+  Status = gCpu->SetMemoryAttributes (gCpu, BaseAddress, EFI_PAGE_SIZE, Attributes);\r
+  ASSERT_EFI_ERROR (Status);\r
   mOnGuarding = FALSE;\r
 }\r
 \r