Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fcicq/409b9d73454e7433784556220622df3b to your computer and use it in GitHub Desktop.
Save fcicq/409b9d73454e7433784556220622df3b to your computer and use it in GitHub Desktop.
From c3f09abd9ad45ce453fec29c68af0e4c68f71e84 Mon Sep 17 00:00:00 2001
From: Nicholas Sherlock <n.sherlock@gmail.com>
Date: Mon, 30 Apr 2018 12:59:13 +1200
Subject: [PATCH] Revert readonly pagetables introduced by 2ac1730 and 147fd35
---
.../Core/DxeIplPeim/Ia32/DxeLoadFunc.c | 6 ------
.../Core/DxeIplPeim/X64/VirtualMemory.c | 6 ------
UefiCpuPkg/CpuDxe/CpuPageTable.c | 21 ++++++++++++-------
3 files changed, 13 insertions(+), 20 deletions(-)
diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
index 172d7cd1c6..803fbf9bb4 100644
--- a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
+++ b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
@@ -143,12 +143,6 @@ Create4GPageTablesIa32Pae (
);
}
- //
- // Protect the page table by marking the memory used for page table to be
- // read-only.
- //
- EnablePageTableProtection ((UINTN)PageMap, FALSE);
-
return (UINTN) PageMap;
}
diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c
index 516cf908bc..97ecbbc814 100644
--- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c
+++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c
@@ -880,12 +880,6 @@ CreateIdentityMappingPageTables (
ZeroMem (PageMapLevel5Entry, (512 - IndexOfPml5Entries) * sizeof (PAGE_MAP_AND_DIRECTORY_POINTER));
}
- //
- // Protect the page table by marking the memory used for page table to be
- // read-only.
- //
- EnablePageTableProtection ((UINTN)PageMap, TRUE);
-
//
// Set IA32_EFER.NXE if necessary.
//
diff --git a/UefiCpuPkg/CpuDxe/CpuPageTable.c b/UefiCpuPkg/CpuDxe/CpuPageTable.c
index ec5cd424fc..27bc4dc130 100644
--- a/UefiCpuPkg/CpuDxe/CpuPageTable.c
+++ b/UefiCpuPkg/CpuDxe/CpuPageTable.c
@@ -1060,7 +1060,6 @@ InitializePageTablePool (
)
{
VOID *Buffer;
- BOOLEAN IsModified;
//
// Do not allow re-entrance.
@@ -1070,7 +1069,6 @@ InitializePageTablePool (
}
mPageTablePoolLock = TRUE;
- IsModified = FALSE;
//
// Always reserve at least PAGE_TABLE_POOL_UNIT_PAGES, including one page for
@@ -1116,17 +1114,16 @@ InitializePageTablePool (
NULL,
(PHYSICAL_ADDRESS)(UINTN)Buffer,
EFI_PAGES_TO_SIZE (PoolPages),
- EFI_MEMORY_RO,
+ 0,
PageActionSet,
AllocatePageTableMemory,
NULL,
- &IsModified
+ NULL
);
- ASSERT (IsModified == TRUE);
Done:
mPageTablePoolLock = FALSE;
- return IsModified;
+ return TRUE;
}
/**
@@ -1347,9 +1344,17 @@ InitializePageTableLib (
if (CurrentPagingContext.ContextData.X64.PageTableBase != 0 &&
(CurrentPagingContext.ContextData.Ia32.Attributes &
PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_PAE) != 0) {
- DisableReadOnlyPageWriteProtect ();
+
+ BOOLEAN IsWpEnabled;
+
+ IsWpEnabled = IsReadOnlyPageWriteProtected ();
+ if (IsWpEnabled) {
+ DisableReadOnlyPageWriteProtect ();
+ }
InitializePageTablePool (1);
- EnableReadOnlyPageWriteProtect ();
+ if (IsWpEnabled) {
+ EnableReadOnlyPageWriteProtect ();
+ }
}
if (HEAP_GUARD_NONSTOP_MODE || NULL_DETECTION_NONSTOP_MODE) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment