Now that the EDK2 tree uses GetMemoryProtectionsLib to query
the platform memory protection settings, OvmfPkg can be updated
to use QemuCfg to set the entire memory protection profile instead
of just SetNxForStack.
For example, the following will set the DXE memory protection to
the RELEASE preset. Other presets are "debug" and "off":
-fw_cfg name=opt/org.tianocore/DxeMemoryProtectionProfile,string=release
The following will set the DXE memory protection to
the RELEASE preset. Other presets are "debug" and "off":
-fw_cfg name=opt/org.tianocore/MmMemoryProtectionProfile,string=release
For users of Stuart, DXE_MEMORY_PROTECTION_PROFILE=release and
MM_MEMORY_PROTECTION_PROFILE=release are equivalent to the above
examples.
Signed-off-by: Taylor Beebe
Cc: Ard Biesheuvel
Cc: Jiewen Yao
Cc: Jordan Justen
Cc: Gerd Hoffmann
Cc: Rebecca Cran
Cc: Peter Grehan
Cc: Corvin Köhne
---
OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c | 56
++--
OvmfPkg/Library/PeilessStartupLib/X64/VirtualMemory.c| 13 +---
OvmfPkg/Library/PlatformInitLib/Platform.c | 15 -
OvmfPkg/Library/QemuFwCfgSimpleParserLib/QemuFwCfgSimpleParser.c | 11 +++
OvmfPkg/PlatformPei/IntelTdx.c | 2 -
OvmfPkg/PlatformPei/Platform.c | 70
++--
OvmfPkg/TdxDxe/TdxDxe.c | 7 +-
OvmfPkg/Bhyve/PlatformPei/PlatformPei.inf| 1 -
OvmfPkg/Include/Library/PlatformInitLib.h| 13
OvmfPkg/Include/Library/QemuFwCfgSimpleParserLib.h | 8 +++
OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf | 1 -
OvmfPkg/PlatformCI/PlatformBuildLib.py | 31 -
OvmfPkg/PlatformPei/PlatformPei.inf | 1 -
OvmfPkg/TdxDxe/TdxDxe.inf| 1 -
14 files changed, 148 insertions(+), 82 deletions(-)
diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c
b/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c
index cf645aad3246..a6ac6a8a15cc 100644
--- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c
+++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartup.c
@@ -28,6 +28,12 @@
#define GET_GPAW_INIT_STATE(INFO) ((UINT8) ((INFO) & 0x3f))
+#define DXE_MEMORY_PROTECTION_PROFILE_FWCFG_FILE \
+ "opt/org.tianocore/DxeMemoryProtectionProfile"
+
+#define MM_MEMORY_PROTECTION_PROFILE_FWCFG_FILE \
+ "opt/org.tianocore/MmMemoryProtectionProfile"
+
EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = {
{ EfiACPIMemoryNVS, 0x004 },
{ EfiACPIReclaimMemory, 0x008 },
@@ -48,6 +54,9 @@ InitializePlatform (
VOID*VariableStore;
DXE_MEMORY_PROTECTION_SETTINGS DxeSettings;
MM_MEMORY_PROTECTION_SETTINGS MmSettings;
+ CHAR8 String[100];
+ UINTN StringSize;
+ EFI_STATUS Status;
DEBUG ((DEBUG_INFO, "InitializePlatform in Pei-less boot\n"));
PlatformDebugDumpCmos ();
@@ -109,18 +118,51 @@ InitializePlatform (
PlatformMemMapInitialization (PlatformInfoHob);
- DxeSettings =
DxeMemoryProtectionProfiles[DxeMemoryProtectionSettingsPcd].Settings;
- MmSettings =
MmMemoryProtectionProfiles[MmMemoryProtectionSettingsPcd].Settings;
- DxeSettings.StackExecutionProtectionEnabled = PcdGetBool (PcdSetNxForStack);
- QemuFwCfgParseBool ("opt/ovmf/PcdSetNxForStack",
&DxeSettings.StackExecutionProtectionEnabled);
+ StringSize = sizeof (String);
- SetDxeMemoryProtectionSettings (&DxeSettings,
DxeMemoryProtectionSettingsPcd);
- SetMmMemoryProtectionSettings (&MmSettings, MmMemoryProtectionSettingsPcd);
+ Status = QemuFwCfgParseString (DXE_MEMORY_PROTECTION_PROFILE_FWCFG_FILE,
&StringSize, String);
+ if (!EFI_ERROR (Status)) {
+DEBUG ((DEBUG_INFO, "Setting DXE Memory Protection Profile: %a\n",
String));
+if (AsciiStriCmp (String, "debug") == 0) {
+ DxeSettings =
DxeMemoryProtectionProfiles[DxeMemoryProtectionSettingsDebug].Settings;
+} else if (AsciiStriCmp (String, "release") == 0) {
+ DxeSettings =
DxeMemoryProtectionProfiles[DxeMemoryProtectionSettingsRelease].Settings;
+} else if (AsciiStriCmp (String, "off") == 0) {
+ DxeSettings =
DxeMemoryProtectionProfiles[DxeMemoryProtectionSettingsOff].Settings;
+} else {
+ DEBUG ((DEBUG_ERROR, "Invalid DXE memory protection profile: %a\n",
String));
+ ASSERT (FALSE);
+}
+ } else {
+DxeSettings =
DxeMemoryProtectionProfiles[DxeMemoryProtectionSettingsDebug].Settings;
+ }
+
+ Status = QemuFwCfgParseString (MM_MEMORY_PROTECTION_PROFILE_FWCFG_FILE,
&StringSize, String);
+ if (!EFI_ERROR (Status)) {
+DEBUG ((DEBUG_INFO, "Setting MM Memory Protection Profile: %a\n", String));
+if (AsciiStriCmp (Strin