]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: PiSmmCore: Inspect memory guarded with pool headers
authorKun Qin <kuqin12@gmail.com>
Tue, 26 Apr 2022 00:47:46 +0000 (08:47 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 13 May 2022 00:51:41 +0000 (00:51 +0000)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3488

Current free pool routine from PiSmmCore will inspect memory guard status
for target buffer without considering pool headers. This could lead to
`IsMemoryGuarded` function to return incorrect results.

In that sense, allocating a 0 sized pool could cause an allocated buffer
directly points into a guard page, which is legal. However, trying to
free this pool will cause the routine changed in this commit to read XP
pages, which leads to page fault.

This change will inspect memory guarded with pool headers. This can avoid
errors when a pool content happens to be on a page boundary.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Kun Qin <kuqin12@gmail.com>
Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
MdeModulePkg/Core/PiSmmCore/Pool.c

index 96ebe811c6695ca89e114f2af4f5d26ab44ca2ca..e1ff40a8ea5570d24a048e357cecd0ef530266be 100644 (file)
@@ -382,11 +382,6 @@ SmmInternalFreePool (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  MemoryGuarded = IsHeapGuardEnabled () &&\r
-                  IsMemoryGuarded ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer);\r
-  HasPoolTail = !(MemoryGuarded &&\r
-                  ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));\r
-\r
   FreePoolHdr = (FREE_POOL_HEADER *)((POOL_HEADER *)Buffer - 1);\r
   ASSERT (FreePoolHdr->Header.Signature == POOL_HEAD_SIGNATURE);\r
   ASSERT (!FreePoolHdr->Header.Available);\r
@@ -394,6 +389,11 @@ SmmInternalFreePool (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  MemoryGuarded = IsHeapGuardEnabled () &&\r
+                  IsMemoryGuarded ((EFI_PHYSICAL_ADDRESS)(UINTN)FreePoolHdr);\r
+  HasPoolTail = !(MemoryGuarded &&\r
+                  ((PcdGet8 (PcdHeapGuardPropertyMask) & BIT7) == 0));\r
+\r
   if (HasPoolTail) {\r
     PoolTail = HEAD_TO_TAIL (&FreePoolHdr->Header);\r
     ASSERT (PoolTail->Signature == POOL_TAIL_SIGNATURE);\r