]> git.proxmox.com Git - mirror_edk2.git/commit
MdeModulePkg/Core: fix a logic hole in page free
authorJian J Wang <jian.j.wang@intel.com>
Wed, 17 Jan 2018 10:36:55 +0000 (18:36 +0800)
committerStar Zeng <star.zeng@intel.com>
Fri, 19 Jan 2018 06:16:11 +0000 (14:16 +0800)
commit425d25699be83c35e12df8470b827d7fbcef3bce
tree8c148e4dd10131ca0d9c70c2a4ea0ab1d41595c1
parentd40695ad82a6a9990d4e73bc9cc3de123eda7a90
MdeModulePkg/Core: fix a logic hole in page free

This hole will cause page fault randomly. The root cause is that Guard
page, which is just freed back to page pool but not yet cleared not-
present attribute, will be allocated right away by internal function
CoreFreeMemoryMapStack(). The solution to this issue is to clear the
not-present attribute for freed Guard page before doing any free
operation, instead of after those operation.

The reason we didn't do this before is due to the fact that manipulating
page attributes might cause memory allocation action which would cause a
dead lock inside a memory allocation/free operation. So we always set or
unset Guard page outside the memory lock. After a thorough analysis, we
believe clearing a Guard page will not cause memory allocation because
memory we're to manipulate was already manipulated before for sure.
Therefore there should be no memory allocation occurring in this
situation.

Since we cleared Guard page not-present attribute before freeing instead
of after freeing, the debug code to clear freed memory can now be restored
to its original way (aka no checking and bypassing Guard page).

Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Star Zeng <star.zeng@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>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
MdeModulePkg/Core/Dxe/Mem/Page.c
MdeModulePkg/Core/Dxe/Mem/Pool.c