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.61419.1629321681105517692 for ; Wed, 18 Aug 2021 14:21:21 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ibm.com header.s=pp1 header.b=pOYIk1M+; spf=pass (domain: linux.ibm.com, ip: 148.163.156.1, mailfrom: tobin@linux.ibm.com) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17IL2xhG028046; Wed, 18 Aug 2021 17:21:16 -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=241YqhCKlxbMG+D+oXQVy2mdYfcxNuYO4wgcNhGcjz0=; b=pOYIk1M+SOc6Q6VRUAx/KG35pS7/pXfjEvCMiw5iH91A8rHSdV+jgJ7+aM6rB89B0s0Z nUuVRa9EZmJ3DKz4B6MDCG/6jx8/LEWBG/yFhVpbynDGNXseRHrtDoznjMnPFri3yZZK j6lD0RiOtkFQkQNjRBDXFCKM9s/Mj35UttWRLHLXulicFNMhMChWNJ4IDXesR8MJCh4H FzpAGw9Mqxqn3jtgDJ0bM3jzGK3fjzbkMRkqbLDL+ScXym4aaWkLh9hFFcrOOaSBK8Sw GUz1MfxBIs5q8Dq3/GKBSVAOJu8qFs10iiBl0oulTPSEI7DGvgprO/S4DrHEMbp5KlO7 /Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3agcsrjft6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Aug 2021 17:21:16 -0400 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 17IL37xx028450; Wed, 18 Aug 2021 17:21:15 -0400 Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com with ESMTP id 3agcsrjfsn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Aug 2021 17:21:15 -0400 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 17ILIJhO002793; Wed, 18 Aug 2021 21:21:14 GMT Received: from b03cxnp07028.gho.boulder.ibm.com (b03cxnp07028.gho.boulder.ibm.com [9.17.130.15]) by ppma03dal.us.ibm.com with ESMTP id 3ae5ffhucb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Aug 2021 21:21:14 +0000 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 17ILLDYE31719906 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 Aug 2021 21:21:13 GMT Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1270EBE04F; Wed, 18 Aug 2021 21:21:13 +0000 (GMT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F1BC5BE056; Wed, 18 Aug 2021 21:21:11 +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:11 +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 6/9] OvmfPkg/AmdSev: Don't overwrite mailbox or pagetables Date: Wed, 18 Aug 2021 17:20:45 -0400 Message-Id: <20210818212048.162626-7-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: MwylJ3fTvh254AuoNNN2iXOqVtr6ZG5J X-Proofpoint-GUID: Bf8eIlRO0wpBjbJhFCu3tAQdLdJWq2XW 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 mlxlogscore=999 mlxscore=0 clxscore=1015 adultscore=0 impostorscore=0 phishscore=0 suspectscore=0 lowpriorityscore=0 spamscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108180130 Content-Transfer-Encoding: 8bit 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 --- .../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