public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdeModulePkg/DxeIpl: Remove clearing CR0.WP when protecting pagetable
@ 2022-08-10  1:24 duntan
  0 siblings, 0 replies; only message in thread
From: duntan @ 2022-08-10  1:24 UTC (permalink / raw)
  To: devel; +Cc: Dandan Bi, Liming Gao, Ray Ni

Remove clearing CR0.WP when marking the memory used for page table
to be read-only in the page table itself created by DxeIpl or
UefiPayloadEntry/UniversalPayloadEntry. This page table address is
written to Cr3 after these protection steps. Till this, the page
table is always RW.

Change-Id: Ibd65fb68ddfa3ea2931004d2d27b6023f457ab46
Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Ray Ni <ray.ni@intel.com>
---
 MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c    | 7 +------
 UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c | 7 +------
 2 files changed, 2 insertions(+), 12 deletions(-)

diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c
index a451ca1604..18b121d768 100644
--- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c
+++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c
@@ -626,12 +626,7 @@ EnablePageTableProtection (
   }
 
   //
-  // Disable write protection, because we need to mark page table to be write
-  // protected.
-  //
-  AsmWriteCr0 (AsmReadCr0 () & ~CR0_WP);
-
-  //
+  // No need to clear CR0.WP since PageTableBase has't been written to CR3 yet.
   // SetPageTablePoolReadOnly might update mPageTablePool. It's safer to
   // remember original one in advance.
   //
diff --git a/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c b/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c
index 74b667a62a..a586941352 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c
@@ -622,12 +622,7 @@ EnablePageTableProtection (
   }
 
   //
-  // Disable write protection, because we need to mark page table to be write
-  // protected.
-  //
-  AsmWriteCr0 (AsmReadCr0 () & ~CR0_WP);
-
-  //
+  // No need to clear CR0.WP since PageTableBase has't been written to CR3 yet.
   // SetPageTablePoolReadOnly might update mPageTablePool. It's safer to
   // remember original one in advance.
   //
-- 
2.31.1.windows.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-08-10  1:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-10  1:24 [PATCH] MdeModulePkg/DxeIpl: Remove clearing CR0.WP when protecting pagetable duntan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox