MdeModulePkg/Core: fix feature conflict between NX and heap guard
authorJian J Wang <jian.j.wang@intel.com>
Mon, 29 Jan 2018 12:03:33 +0000 (20:03 +0800)
committerStar Zeng <star.zeng@intel.com>
Fri, 2 Feb 2018 01:50:16 +0000 (09:50 +0800)
commita6a0a59756173148099d66638fcb4b3bca52434b
tree2c4055fc940cbf9d7e6f3870aee4a3b88db19c63
parent9b17c6511d50db493c49324aaf81c50c3676a111
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>
MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
MdeModulePkg/Core/Dxe/Mem/HeapGuard.h
MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c