[edk2-devel] [RFC PATCH 7/9] OvmfPkg/AmdSev: Don't overwrite MH stack

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


The Migration Handler uses its own stack and should avoid
overwriting the stack when importing pages.

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

diff --git a/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c
index ee1466eb00..2de35a7bb1 100644
--- a/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c
+++ b/OvmfPkg/AmdSev/ConfidentialMigration/ConfidentialMigrationDxe.c
@@ -45,6 +45,8 @@ typedef volatile struct {
 
 STATIC PAGE_TABLE_POOL   *mPageTablePool = NULL;
 PHYSICAL_ADDRESS  mMigrationHandlerPageTables = 0;
+PHYSICAL_ADDRESS  mMigrationHandlerStackBase = 0;
+UINT32            mMigrationHandlerStackSize = 4;
 
 /**
   Allocates and fills in custom page tables for Migration Handler.
@@ -112,6 +114,8 @@ MigrationHandlerMain ()
   UINT64                       MailboxEnd;
   UINT64                       PagetableStart;
   UINT64                       PagetableEnd;
+  UINT64                       StackStart;
+  UINT64                       StackEnd;
   MH_COMMAND_PARAMETERS        *Params;
   VOID                         *PageVa;
 
@@ -126,6 +130,9 @@ MigrationHandlerMain ()
   PagetableStart = mMigrationHandlerPageTables;
   PagetableEnd = PagetableStart + 11 * EFI_PAGE_SIZE;
 
+  StackStart = mMigrationHandlerStackBase;
+  StackEnd = StackStart + mMigrationHandlerStackSize;
+
   DisableInterrupts ();
   Params->Go = 0;
 
@@ -147,10 +154,11 @@ MigrationHandlerMain ()
 
     case MH_FUNC_RESTORE_PAGE:
       //
-      // Don't import a page that covers the mailbox or pagetables.
+      // Don't import a page that covers the mailbox, pagetables, or stack.
       //
       if (!((Params->Gpa >= MailboxStart && Params->Gpa < MailboxEnd) ||
-          (Params->Gpa >= PagetableStart && Params->Gpa < PagetableEnd))) {
+          (Params->Gpa >= PagetableStart && Params->Gpa < PagetableEnd) ||
+          (Params->Gpa >= StackStart && Params->Gpa < StackEnd))) {
 
         CopyMem ((VOID *)Params->Gpa, PageVa, 4096);
       }
@@ -190,6 +198,11 @@ SetupMigrationHandler (
     return 0;
   }
 
+  //
+  // Setup stack and pagetables for Migration Handler
+  //
+  mMigrationHandlerStackBase = (UINTN)AllocateAlignedRuntimePages (mMigrationHandlerStackSize, PAGE_TABLE_POOL_ALIGNMENT);
+
 	PrepareMigrationHandlerPageTables ();
 
   //
-- 
2.20.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#79524): https://edk2.groups.io/g/devel/message/79524
Mute This Topic: https://groups.io/mt/84982987/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