/** @file\r
Page table manipulation functions for IA-32 processors\r
\r
-Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>\r
Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>\r
\r
This program and the accompanying materials\r
\r
#include "PiSmmCpuDxeSmm.h"\r
\r
+/**\r
+ Disable CET.\r
+**/\r
+VOID\r
+EFIAPI\r
+DisableCet (\r
+ VOID\r
+ );\r
+\r
+/**\r
+ Enable CET.\r
+**/\r
+VOID\r
+EFIAPI\r
+EnableCet (\r
+ VOID\r
+ );\r
+\r
/**\r
Create PageTable for SMM use.\r
\r
}\r
}\r
CpuDeadLoop ();\r
+ goto Exit;\r
}\r
\r
//\r
DumpModuleInfoByIp (*(UINTN *)(UINTN)SystemContext.SystemContextIa32->Esp);\r
);\r
CpuDeadLoop ();\r
+ goto Exit;\r
}\r
\r
//\r
}\r
\r
CpuDeadLoop ();\r
+ goto Exit;\r
}\r
\r
if (IsSmmCommBufferForbiddenAddress (PFAddress)) {\r
DumpModuleInfoByIp ((UINTN)SystemContext.SystemContextIa32->Eip);\r
);\r
CpuDeadLoop ();\r
+ goto Exit;\r
}\r
}\r
\r
UINT64 *L3PageTable;\r
BOOLEAN IsSplitted;\r
BOOLEAN PageTableSplitted;\r
+ BOOLEAN CetEnabled;\r
\r
//\r
// Don't mark page table to read-only if heap guard is enabled.\r
// Disable write protection, because we need mark page table to be write protected.\r
// We need *write* page table memory, to mark itself to be *read only*.\r
//\r
+ CetEnabled = ((AsmReadCr4() & CR4_CET_ENABLE) != 0) ? TRUE : FALSE;\r
+ if (CetEnabled) {\r
+ //\r
+ // CET must be disabled if WP is disabled.\r
+ //\r
+ DisableCet();\r
+ }\r
AsmWriteCr0 (AsmReadCr0() & ~CR0_WP);\r
\r
do {\r
// Enable write protection, after page table updated.\r
//\r
AsmWriteCr0 (AsmReadCr0() | CR0_WP);\r
+ if (CetEnabled) {\r
+ //\r
+ // re-enable CET.\r
+ //\r
+ EnableCet();\r
+ }\r
\r
return ;\r
}\r