From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 5D0B1D801EC for ; Mon, 26 Feb 2024 05:19:14 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=x1Cv7995oOmLkEQL1AlMvmIl0aR8wssiiIdH8RDAaWc=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1708924753; v=1; b=vFBkfLgZpNwxkMyLDJRrhgZP/9CFbz7jjwdLj2Tq3sWMD4O9NEguYbu4NO5lJPPsS5ST0VoG PUb08MIpRH3XIt+UZ8aI9Zn9jlEdpVoy2fHXBMrQYDquPfxJ3PIpzkBN9/aILtCY0snlpR0ZwaK q2STv+r+hlkjskgJtlUUi56E= X-Received: by 127.0.0.2 with SMTP id 2K1jYY7687511xw4hQ08cGh2; Sun, 25 Feb 2024 21:19:13 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) by mx.groups.io with SMTP id smtpd.web11.14433.1708924752559985154 for ; Sun, 25 Feb 2024 21:19:12 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="3344964" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="3344964" X-Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Feb 2024 21:19:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="7052079" X-Received: from tdvf-default-string.sh.intel.com ([10.239.49.7]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Feb 2024 21:19:09 -0800 From: "sunceping" To: devel@edk2.groups.io Cc: Ceping Sun , Erdem Aktas , James Bottomley , Jiewen Yao , Min Xu , Tom Lendacky , Michael Roth , Gerd Hoffmann , Isaku Yamahata Subject: [edk2-devel] [PATCH V1 3/3] OvmfPkg/TdxDxe: Clear the registers before tdcall Date: Tue, 27 Feb 2024 05:18:33 +0800 Message-Id: <20240226211833.3156606-4-cepingx.sun@intel.com> In-Reply-To: <20240226211833.3156606-1-cepingx.sun@intel.com> References: <20240226211833.3156606-1-cepingx.sun@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,cepingx.sun@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: YuGLy6RebaEI2mH2QIqkgk1Kx7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=vFBkfLgZ; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none) REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4696 Refer to the [GHCI] spec, TDVF should clear the BIT5 for RBP in the mask. And TDVF should clear the regitsers to avoid leaking secrets to VMM. Reference: [GHCI]: TDX Guest-Host-Communication Interface v1.5 https://cdrdv2.intel.com/v1/dl/getContent/726792 Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Min Xu Cc: Tom Lendacky Cc: Michael Roth Cc: Gerd Hoffmann Cc: Erdem Aktas Cc: Isaku Yamahata Signed-off-by: Ceping Sun --- OvmfPkg/TdxDxe/X64/ApRunLoop.nasm | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/OvmfPkg/TdxDxe/X64/ApRunLoop.nasm b/OvmfPkg/TdxDxe/X64/ApRunLoop.nasm index 0bef89c48552..57560015f491 100644 --- a/OvmfPkg/TdxDxe/X64/ApRunLoop.nasm +++ b/OvmfPkg/TdxDxe/X64/ApRunLoop.nasm @@ -20,7 +20,7 @@ SECTION .text BITS 64 -%define TDVMCALL_EXPOSE_REGS_MASK 0xffec +%define TDVMCALL_EXPOSE_REGS_MASK 0xffcc %define TDVMCALL 0x0 %define EXIT_REASON_CPUID 0xa @@ -28,6 +28,30 @@ BITS 64 db 0x66, 0x0f, 0x01, 0xcc %endmacro +%macro tdcall_regs_preamble 2 + mov rax, %1 + + xor rcx, rcx + mov ecx, %2 + + ; R10 = 0 (standard TDVMCALL) + + xor r10d, r10d + + ; Zero out unused (for standard TDVMCALL) registers to avoid leaking + ; secrets to the VMM. + + xor esi, esi + xor edi, edi + + xor edx, edx + xor ebp, ebp + xor r8d, r8d + xor r9d, r9d + xor r14, r14 + xor r15, r15 +%endmacro + ; ; Relocated Ap Mailbox loop ; @@ -40,11 +64,9 @@ global ASM_PFX(AsmRelocateApMailBoxLoop) ASM_PFX(AsmRelocateApMailBoxLoop): AsmRelocateApMailBoxLoopStart: - mov rax, TDVMCALL - mov rcx, TDVMCALL_EXPOSE_REGS_MASK - xor r10, r10 mov r11, EXIT_REASON_CPUID mov r12, 0xb + tdcall_regs_preamble TDVMCALL, TDVMCALL_EXPOSE_REGS_MASK tdcall test r10, r10 jnz Panic -- 2.34.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115944): https://edk2.groups.io/g/devel/message/115944 Mute This Topic: https://groups.io/mt/104577524/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-