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 <ray.ni@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
---
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..d7d94c8b6d 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.
+ // Protect memory outside SMRAM when SMM Static Page Table is enabled.
//
- SetUefiMemMapAttributes ();
+ if (IsStaticPageTableEnabled ()) {
- //
- // 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.
--
2.21.0.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#44470): https://edk2.groups.io/g/devel/message/44470
Mute This Topic: https://groups.io/mt/32616003/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
On 07/27/19 05:28, Ni, Ray wrote:
> 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 <ray.ni@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> ---
> 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..d7d94c8b6d 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.
> + // Protect memory outside SMRAM when SMM Static Page Table is enabled.
> //
> - SetUefiMemMapAttributes ();
> + if (IsStaticPageTableEnabled ()) {
>
> - //
> - // 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.
>
With the IA32 bug in patch#1 fixed, this patch will also do the right
thing (as part of OVMF anyway):
- on IA32, there will be no change in behavior
(IsStaticPageTableEnabled() will evaluate to constant TRUE)
- on X64, OVMF keeps the DEC-default TRUE value for the underlying PCD
(PcdCpuSmmStaticPageTable), hence IsStaticPageTableEnabled() will return
TRUE, and the behavior won't change.
Because I cannot validate the PcdCpuSmmStaticPageTable==FALSE case, I
won't give R-b. But I can certainly give:
Acked-by: Laszlo Ersek <lersek@redhat.com>
Thanks!
Laszlo
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#44517): https://edk2.groups.io/g/devel/message/44517
Mute This Topic: https://groups.io/mt/32616003/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Reviewed-by: Eric Dong <eric.dong@intel.com>
> -----Original Message-----
> From: Ni, Ray
> Sent: Saturday, July 27, 2019 11:29 AM
> To: devel@edk2.groups.io
> Cc: Dong, Eric <eric.dong@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>;
> Wang, Jian J <jian.j.wang@intel.com>
> Subject: [PATCH 3/3] 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 <ray.ni@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> ---
> 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..d7d94c8b6d 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.
> + // Protect memory outside SMRAM when SMM Static Page Table is
> enabled.
> //
> - SetUefiMemMapAttributes ();
> + if (IsStaticPageTableEnabled ()) {
>
> - //
> - // 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.
> --
> 2.21.0.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#44515): https://edk2.groups.io/g/devel/message/44515
Mute This Topic: https://groups.io/mt/32616003/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2026 Red Hat, Inc.