From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by mx.groups.io with SMTP id smtpd.web10.61420.1629321682316478233 for ; Wed, 18 Aug 2021 14:21:22 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ibm.com header.s=pp1 header.b=YNTx2Vl9; spf=pass (domain: linux.ibm.com, ip: 148.163.156.1, mailfrom: tobin@linux.ibm.com) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17IL3Ngt156667; Wed, 18 Aug 2021 17:21:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=6x0Q3837BjCP8P5KK/8fGZ+LAKJJ/PertYoJa3/1jhA=; b=YNTx2Vl9rGY0SLwXAiAvJOrrX2i5GJzxKFu+0O3k1eaZ9M6GXLhYy/Bes6CTdYrM+qC9 r18Syfnciw5W+KfSsoevB8BLA0qvQ+3ylP/FMbjETnLYXJ9cUbyZ1aJek2Qh/3OpwiKB al3P7k5q92IPdv/pkO3SHuxtogRuQDGDLTgkYgYdFyBtf0KISBjyTmWm1DPGFt19Su6P 9iT9U0OzBKsY6t0PAMMSBUzxUfzjAi3Nn9LObfz518hEMmBpbMugJPQOv1YEY/xFO/bB IC/4r0a9eVstg5w64fhpoDcf1BAX4NWSyyYgcuLelVKiLsirEM09y6i3T3FOmic4Rgyo Iw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3agcvsj97g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Aug 2021 17:21:17 -0400 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 17IL3VAT157371; Wed, 18 Aug 2021 17:21:17 -0400 Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0a-001b2d01.pphosted.com with ESMTP id 3agcvsj96p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Aug 2021 17:21:17 -0400 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 17ILI7hY021080; Wed, 18 Aug 2021 21:21:15 GMT Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17]) by ppma05wdc.us.ibm.com with ESMTP id 3ae5fdw9fy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Aug 2021 21:21:15 +0000 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 17ILLEsI51380620 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 Aug 2021 21:21:14 GMT Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4A854BE04F; Wed, 18 Aug 2021 21:21:14 +0000 (GMT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 351ECBE053; Wed, 18 Aug 2021 21:21:13 +0000 (GMT) Received: from amdrome1.watson.ibm.com (unknown [9.2.130.16]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 18 Aug 2021 21:21:13 +0000 (GMT) From: "Tobin Feldman-Fitzthum" To: tobin@ibm.com, dovmurik@linux.vnet.ibm.com, jejb@linux.ibm.com, frankeh@us.ibm.com, pbonzini@redhat.com, ashish.kalra@amd.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, dgilbert@redhat.com, srutherford@google.com, devel@edk2.groups.io, ard.biesheuvel@arm.com, jiewen.yao@intel.com Subject: [RFC PATCH 7/9] OvmfPkg/AmdSev: Don't overwrite MH stack Date: Wed, 18 Aug 2021 17:20:46 -0400 Message-Id: <20210818212048.162626-8-tobin@linux.ibm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210818212048.162626-1-tobin@linux.ibm.com> References: <20210818212048.162626-1-tobin@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: PpAhBoufF4cbi7FDEdp3sJFfzpKWnFG3 X-Proofpoint-GUID: 73K_IK9aGSpoQpAlu9iARgrwc2WgpiBx X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-08-18_07:2021-08-17,2021-08-18 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1015 suspectscore=0 mlxscore=0 mlxlogscore=999 phishscore=0 priorityscore=1501 malwarescore=0 impostorscore=0 bulkscore=0 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108180130 Content-Transfer-Encoding: 8bit The Migration Handler uses its own stack and should avoid overwriting the stack when importing pages. Signed-off-by: Tobin Feldman-Fitzthum --- .../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