From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web11.3974.1666945473912633374 for ; Fri, 28 Oct 2022 01:24:34 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=DwPKBT3e; spf=pass (domain: intel.com, ip: 134.134.136.24, mailfrom: min.m.xu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666945473; x=1698481473; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=RlcufahroHnU7x22rcUYF8LAWjRXJDxEytbVRoOecmE=; b=DwPKBT3eboUqg3WKl0mKs5hPDPJ9+f1D9bFniHIwNjegFKcSUyE44eAu 0gd3QfCwtz3QIrKsxb0JCs9sepqpNkfQy83QucHephvRQ06e5LVWww+F2 yi35m8FAk7y6pp0kOzWpwAauEbnUj0imaQy6y9gjapi6eUhRcp5vjXjwJ aGiz6rI4MVRfCPHisKuUQHfmcm6jxjqD5CzfPZv56xaJbyvZYC8MZMeyc DQKYCEkiFlAXF+6EoGxlLSjnbTt+zpSHh9HJynivo9aVhQiecYNcjSFWt vgh+XcpkIdeMGZ+rS40L1d77d3ak7eCq8dIJFAJpL8lU9wySfHtwewdKc g==; X-IronPort-AV: E=McAfee;i="6500,9779,10513"; a="309533483" X-IronPort-AV: E=Sophos;i="5.95,220,1661842800"; d="scan'208";a="309533483" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2022 01:24:24 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10513"; a="665991517" X-IronPort-AV: E=Sophos;i="5.95,220,1661842800"; d="scan'208";a="665991517" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.97]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2022 01:24:22 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [PATCH V2 1/1] OvmfPkg/VmgExitLig: HALT on #VE when access to private memory Date: Fri, 28 Oct 2022 16:24:01 +0800 Message-Id: <20221028082401.1227-1-min.m.xu@intel.com> X-Mailer: git-send-email 2.29.2.windows.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Min M Xu BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4125 EPT-violation #VE should be always on shared memory, which means the shared bit of the GuestPA should be set. But in current #VE Handler it is not checked. When it occurs, stop TD immediately and log out the error. Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Min Xu --- .../Library/VmgExitLib/VmTdExitVeHandler.c | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/OvmfPkg/Library/VmgExitLib/VmTdExitVeHandler.c b/OvmfPkg/Library/VmgExitLib/VmTdExitVeHandler.c index b73e877c093b..c89268c5d8e8 100644 --- a/OvmfPkg/Library/VmgExitLib/VmTdExitVeHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmTdExitVeHandler.c @@ -300,23 +300,41 @@ MmioExit ( IN TDCALL_VEINFO_RETURN_DATA *Veinfo ) { - UINT64 Status; - UINT32 MmioSize; - UINT32 RegSize; - UINT8 OpCode; - BOOLEAN SeenRex; - UINT64 *Reg; - UINT8 *Rip; - UINT64 Val; - UINT32 OpSize; - MODRM ModRm; - REX Rex; + UINT64 Status; + UINT32 MmioSize; + UINT32 RegSize; + UINT8 OpCode; + BOOLEAN SeenRex; + UINT64 *Reg; + UINT8 *Rip; + UINT64 Val; + UINT32 OpSize; + MODRM ModRm; + REX Rex; + TD_RETURN_DATA TdReturnData; + UINT8 Gpaw; + UINT64 TdSharedPageMask; Rip = (UINT8 *)Regs->Rip; Val = 0; Rex.Val = 0; SeenRex = FALSE; + Status = TdCall (TDCALL_TDINFO, 0, 0, 0, &TdReturnData); + if (Status == TDX_EXIT_REASON_SUCCESS) { + Gpaw = (UINT8)(TdReturnData.TdInfo.Gpaw & 0x3f); + TdSharedPageMask = 1ULL << (Gpaw - 1); + } else { + DEBUG ((DEBUG_ERROR, "TDCALL failed with status=%llx\n", Status)); + return Status; + } + + if ((Veinfo->GuestPA & TdSharedPageMask) == 0) { + DEBUG ((DEBUG_ERROR, "EPT-violation #VE on private memory is not allowed!")); + TdVmCall (TDVMCALL_HALT, 0, 0, 0, 0, 0); + CpuDeadLoop (); + } + // // Default to 32bit transfer // -- 2.29.2.windows.2