From 8c9983977676d68466c770846d3e64470b3d8668 Mon Sep 17 00:00:00 2001 From: Dun Tan Date: Tue, 16 May 2023 15:51:50 +0800 Subject: [PATCH] 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 Cc: Liming Gao Cc: Ray Ni Reviewed-by: Jian J Wang Cc: Ard Biesheuvel --- MdeModulePkg/Core/PiSmmCore/HeapGuard.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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; } }