public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Min Xu" <min.m.xu@intel.com>
To: "Sun, CepingX" <cepingx.sun@intel.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "Aktas, Erdem" <erdemaktas@google.com>,
	James Bottomley <jejb@linux.ibm.com>,
	"Yao, Jiewen" <jiewen.yao@intel.com>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	Michael Roth <michael.roth@amd.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	"Yamahata, Isaku" <isaku.yamahata@intel.com>
Subject: Re: [edk2-devel] [PATCH V1 3/3] OvmfPkg/TdxDxe: Clear the registers before tdcall
Date: Mon, 4 Mar 2024 01:09:24 +0000	[thread overview]
Message-ID: <PH0PR11MB5064AA3612542E8C9385CE3BC5232@PH0PR11MB5064.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20240226211833.3156606-4-cepingx.sun@intel.com>

Reviewed-by: Min Xu <min.m.xu@intel.com>

> -----Original Message-----
> From: Sun, CepingX <cepingx.sun@intel.com>
> Sent: Tuesday, February 27, 2024 5:19 AM
> To: devel@edk2.groups.io
> Cc: Sun, CepingX <cepingx.sun@intel.com>; Aktas, Erdem
> <erdemaktas@google.com>; James Bottomley <jejb@linux.ibm.com>; Yao,
> Jiewen <jiewen.yao@intel.com>; Xu, Min M <min.m.xu@intel.com>; Tom
> Lendacky <thomas.lendacky@amd.com>; Michael Roth
> <michael.roth@amd.com>; Gerd Hoffmann <kraxel@redhat.com>;
> Yamahata, Isaku <isaku.yamahata@intel.com>
> Subject: [PATCH V1 3/3] OvmfPkg/TdxDxe: Clear the registers before tdcall
> 
> 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 <erdemaktas@google.com>
> Cc: James Bottomley <jejb@linux.ibm.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Min Xu <min.m.xu@intel.com>
> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> Cc: Michael Roth <michael.roth@amd.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Erdem Aktas <erdemaktas@google.com>
> Cc: Isaku Yamahata <isaku.yamahata@intel.com>
> Signed-off-by: Ceping Sun <cepingx.sun@intel.com>
> ---
>  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 (#116294): https://edk2.groups.io/g/devel/message/116294
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]
-=-=-=-=-=-=-=-=-=-=-=-



  parent reply	other threads:[~2024-03-04  1:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-26 21:18 [edk2-devel] [PATCH V1 0/3] OvmfPkg: Update TDVMCALL to avoid leaking secrets to the VMM sunceping
2024-02-26 21:18 ` [edk2-devel] [PATCH V1 1/3] MdePkg/BaseLib: Update TDVMCALL_EXPOSE_REGS_MASK sunceping
2024-03-04  1:09   ` Min Xu
2024-03-04  3:22   ` sunceping
2024-03-13  7:32     ` sunceping
2024-03-14 14:33   ` 回复: " gaoliming via groups.io
2024-02-26 21:18 ` [edk2-devel] [PATCH V1 2/3] OvmfPkg/CcExitLib: " sunceping
2024-03-04  1:09   ` Min Xu
2024-02-26 21:18 ` [edk2-devel] [PATCH V1 3/3] OvmfPkg/TdxDxe: Clear the registers before tdcall sunceping
2024-02-27 12:25   ` Isaku Yamahata
2024-02-28  8:27     ` sunceping
2024-03-04  1:09   ` Min Xu [this message]
2024-02-27  6:48 ` [edk2-devel] [PATCH V1 0/3] OvmfPkg: Update TDVMCALL to avoid leaking secrets to the VMM Min Xu
2024-03-12  5:53   ` Yao, Jiewen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=PH0PR11MB5064AA3612542E8C9385CE3BC5232@PH0PR11MB5064.namprd11.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox