[edk2-devel] [RFC PATCH 6/9] OvmfPkg/AmdSev: Don't overwrite mailbox or pagetables

Tobin Feldman-Fitzthum tobin at linux.ibm.com
Wed Aug 18 21:20:45 UTC 2021


While restoring pages, the MH should avoid overwriting its
pagetables or the mailbox it uses to communicate with the HV.

Signed-off-by: Tobin Feldman-Fitzthum <tobin at linux.ibm.com>
---
 .../ConfidentialMigrationDxe.c                  | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c
index 34d449fe10..ee1466eb00 100644
--- a/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c
+++ b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c
@@ -109,6 +109,9 @@ EFIAPI
 MigrationHandlerMain ()
 {
   UINT64                       MailboxStart;
+  UINT64                       MailboxEnd;
+  UINT64                       PagetableStart;
+  UINT64                       PagetableEnd;
   MH_COMMAND_PARAMETERS        *Params;
   VOID                         *PageVa;
 
@@ -118,6 +121,11 @@ MigrationHandlerMain ()
   Params = (VOID *)(MailboxStart + UNENC_VIRT_ADDR_BASE);
   PageVa = (VOID *)(MailboxStart + UNENC_VIRT_ADDR_BASE + 0x1000);
 
+  MailboxEnd = MailboxStart + 2 * EFI_PAGE_SIZE;
+
+  PagetableStart = mMigrationHandlerPageTables;
+  PagetableEnd = PagetableStart + 11 * EFI_PAGE_SIZE;
+
   DisableInterrupts ();
   Params->Go = 0;
 
@@ -138,7 +146,14 @@ MigrationHandlerMain ()
       break;
 
     case MH_FUNC_RESTORE_PAGE:
-      CopyMem ((VOID *)Params->Gpa, PageVa, 4096);
+      //
+      // Don't import a page that covers the mailbox or pagetables.
+      //
+      if (!((Params->Gpa >= MailboxStart && Params->Gpa < MailboxEnd) ||
+          (Params->Gpa >= PagetableStart && Params->Gpa < PagetableEnd))) {
+
+        CopyMem ((VOID *)Params->Gpa, PageVa, 4096);
+      }
       Params->Ret = MH_SUCCESS;
       break;
 
-- 
2.20.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#79523): https://edk2.groups.io/g/devel/message/79523
Mute This Topic: https://groups.io/mt/84982986/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-





More information about the edk2-devel-archive mailing list