summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDun Tan <dun.tan@intel.com>2023-05-16 15:51:50 +0800
committerRay Ni <ray.ni@intel.com>2023-06-30 11:07:40 +0530
commit8c9983977676d68466c770846d3e64470b3d8668 (patch)
tree6bdf3bf913e5a6ec3bf05945bb6276d1a8a50258
parenta78938f2740dd969e2f03846a9bd2167e7e582c3 (diff)
downloadedk2-8c9983977676d68466c770846d3e64470b3d8668.tar.gz
edk2-8c9983977676d68466c770846d3e64470b3d8668.tar.bz2
edk2-8c9983977676d68466c770846d3e64470b3d8668.zip
MdeModulePkg: Remove other attribute protection in UnsetGuardPage
In UnsetGuardPage(), before SmmReadyToLock, remove NX and RO memory attribute protection for guarded page since EfiConventionalMemory in SMRAM is RW and executable before SmmReadyToLock. If UnsetGuardPage() happens after SmmReadyToLock, then apply EFI_MEMORY_XP to the guarded page to make sure EfiConventionalMemory in SMRAM is NX since EfiConventionalMemory in SMRAM is marked as NX in PiSmmCpuDxe driver when SmmReadyToLock. Signed-off-by: Dun Tan <dun.tan@intel.com> Cc: Liming Gao <gaoliming@byosoft.com.cn> Cc: Ray Ni <ray.ni@intel.com> Reviewed-by: Jian J Wang <jian.j.wang@intel.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
-rw-r--r--MdeModulePkg/Core/PiSmmCore/HeapGuard.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/MdeModulePkg/Core/PiSmmCore/HeapGuard.c b/MdeModulePkg/Core/PiSmmCore/HeapGuard.c
index 8f3bab6fee..25310122ca 100644
--- a/MdeModulePkg/Core/PiSmmCore/HeapGuard.c
+++ b/MdeModulePkg/Core/PiSmmCore/HeapGuard.c
@@ -553,9 +553,23 @@ UnsetGuardPage (
mSmmMemoryAttribute,
BaseAddress,
EFI_PAGE_SIZE,
- EFI_MEMORY_RP
+ EFI_MEMORY_RP|EFI_MEMORY_RO|EFI_MEMORY_XP
);
ASSERT_EFI_ERROR (Status);
+
+ if (gST == NULL) {
+ //
+ // Make sure EfiConventionalMemory is NX after SmmReadyToLock
+ //
+ Status = mSmmMemoryAttribute->SetMemoryAttributes (
+ mSmmMemoryAttribute,
+ BaseAddress,
+ EFI_PAGE_SIZE,
+ EFI_MEMORY_XP
+ );
+ ASSERT_EFI_ERROR (Status);
+ }
+
mOnGuarding = FALSE;
}
}