mirror of https://github.com/acidanthera/audk.git
UefiCpuPkg/PiSmmCpuDxeSmm:Fix PF issue caused by smm page table code
When setting new page table pool to RO, only disable/enable WP when
Cr0.WP has been set to 1 to fix potential PF caused by b822be1a20
(UefiCpuPkg/PiSmmCpuDxeSmm: Introduce page table pool mechanism).
With previous code, if someone want to modify the page table and
Cr0.WP has been cleared before modify page table, Cr0.WP may be set
to 1 again since new pool may be generated during this process
Then PF fault may happens.
Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
This commit is contained in:
parent
bbd30066e1
commit
b670700ddf
|
@ -69,6 +69,8 @@ InitializePageTablePool (
|
||||||
{
|
{
|
||||||
VOID *Buffer;
|
VOID *Buffer;
|
||||||
BOOLEAN CetEnabled;
|
BOOLEAN CetEnabled;
|
||||||
|
BOOLEAN WpEnabled;
|
||||||
|
IA32_CR0 Cr0;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Always reserve at least PAGE_TABLE_POOL_UNIT_PAGES, including one page for
|
// Always reserve at least PAGE_TABLE_POOL_UNIT_PAGES, including one page for
|
||||||
|
@ -106,16 +108,26 @@ InitializePageTablePool (
|
||||||
//
|
//
|
||||||
if (mIsReadOnlyPageTable) {
|
if (mIsReadOnlyPageTable) {
|
||||||
CetEnabled = ((AsmReadCr4 () & CR4_CET_ENABLE) != 0) ? TRUE : FALSE;
|
CetEnabled = ((AsmReadCr4 () & CR4_CET_ENABLE) != 0) ? TRUE : FALSE;
|
||||||
|
Cr0.UintN = AsmReadCr0 ();
|
||||||
|
WpEnabled = (Cr0.Bits.WP != 0) ? TRUE : FALSE;
|
||||||
|
if (WpEnabled) {
|
||||||
if (CetEnabled) {
|
if (CetEnabled) {
|
||||||
//
|
//
|
||||||
// CET must be disabled if WP is disabled.
|
// CET must be disabled if WP is disabled. Disable CET before clearing CR0.WP.
|
||||||
//
|
//
|
||||||
DisableCet ();
|
DisableCet ();
|
||||||
}
|
}
|
||||||
|
|
||||||
AsmWriteCr0 (AsmReadCr0 () & ~CR0_WP);
|
Cr0.Bits.WP = 0;
|
||||||
|
AsmWriteCr0 (Cr0.UintN);
|
||||||
|
}
|
||||||
|
|
||||||
SmmSetMemoryAttributes ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, EFI_PAGES_TO_SIZE (PoolPages), EFI_MEMORY_RO);
|
SmmSetMemoryAttributes ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, EFI_PAGES_TO_SIZE (PoolPages), EFI_MEMORY_RO);
|
||||||
AsmWriteCr0 (AsmReadCr0 () | CR0_WP);
|
if (WpEnabled) {
|
||||||
|
Cr0.UintN = AsmReadCr0 ();
|
||||||
|
Cr0.Bits.WP = 1;
|
||||||
|
AsmWriteCr0 (Cr0.UintN);
|
||||||
|
|
||||||
if (CetEnabled) {
|
if (CetEnabled) {
|
||||||
//
|
//
|
||||||
// re-enable CET.
|
// re-enable CET.
|
||||||
|
@ -123,6 +135,7 @@ InitializePageTablePool (
|
||||||
EnableCet ();
|
EnableCet ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue