MdeModulePkg/Core: fix feature conflict between NX and heap guard

Considering following scenario (both NX memory protection and heap guard
are enabled):

   1. Allocate 3 pages. The attributes of adjacent memory pages will be

      |NOT-PRESENT|  present  |  present  |  present  |NOT-PRESENT|

   2. Free the middle page. The attributes of adjacent memory pages should be

      |NOT-PRESENT|  present  |NOT-PRESENT|  present  |NOT-PRESENT|

      But the NX feature will overwrite the attributes of middle page. So it
      looks still like below, which is wrong.

      |NOT-PRESENT|  present  |  PRESENT  |  present  |NOT-PRESENT|

The solution is checking the first and/or last page of a memory block to be
marked as NX, and skipping them if they are Guard pages.

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: Ruiyu Ni <ruiyu.ni@intel.com>
(cherry picked from commit a6a0a59756)
This commit is contained in:
Jian J Wang
2018-01-29 20:03:33 +08:00
committed by Star Zeng
parent 3f251a864a
commit 4fa13b6957
3 changed files with 46 additions and 0 deletions

View File

@@ -389,6 +389,16 @@ AdjustPoolHeadF (
IN EFI_PHYSICAL_ADDRESS Memory
);
/**
Check to see if the heap guard is enabled for page and/or pool allocation.
@return TRUE/FALSE.
**/
BOOLEAN
IsHeapGuardEnabled (
VOID
);
extern BOOLEAN mOnGuarding;
#endif