From 30f6148546c7092650ab4886fc6d95d5065c3188 Mon Sep 17 00:00:00 2001 From: "Ni, Ray" Date: Thu, 18 Jul 2019 14:58:07 +0800 Subject: [PATCH] UefiCpuPkg/PiSmmCpu: Allow SMM access-out when static paging is OFF Commit c60d36b4d1ee1f69b7cca897d3621dfa951895c2 * UefiCpuPkg/SmmCpu: Block access-out only when static paging is used updated page fault handler to treat SMM access-out as allowed address when static paging is not used. But that commit is not complete because the page table is still updated in SetUefiMemMapAttributes() for non-SMRAM memory. When SMM code accesses non-SMRAM memory, page fault is still generated. This patch skips to update page table for non-SMRAM memory and page table itself. Signed-off-by: Ray Ni Cc: Eric Dong Cc: Jiewen Yao Cc: Jian J Wang Acked-by: Laszlo Ersek Reviewed-by: Eric Dong --- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c index 69a04dfb23..50614f32c3 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c @@ -1121,6 +1121,9 @@ FindSmramInfo ( *SmrrBase = (UINT32)CurrentSmramRange->CpuStart; *SmrrSize = (UINT32)CurrentSmramRange->PhysicalSize; + // + // Extend *SmrrBase/*SmrrSize to include adjacent SMRAM ranges + // do { Found = FALSE; for (Index = 0; Index < mSmmCpuSmramRangeCount; Index++) { @@ -1432,14 +1435,20 @@ PerformRemainingTasks ( SetMemMapAttributes (); // - // For outside SMRAM, we only map SMM communication buffer or MMIO. + // Do not protect memory outside SMRAM when SMM static page table is not enabled. // - SetUefiMemMapAttributes (); + if (mCpuSmmStaticPageTable) { - // - // Set page table itself to be read-only - // - SetPageTableAttributes (); + // + // For outside SMRAM, we only map SMM communication buffer or MMIO. + // + SetUefiMemMapAttributes (); + + // + // Set page table itself to be read-only + // + SetPageTableAttributes (); + } // // Configure SMM Code Access Check feature if available.