From: Tom Lendacky <thomas.lendacky@amd.com>
To: Joerg Roedel <joro@8bytes.org>, x86@kernel.org
Cc: Joerg Roedel <jroedel@suse.de>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
"H. Peter Anvin" <hpa@zytor.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Kees Cook <keescook@chromium.org>,
Arvind Sankar <nivedita@alum.mit.edu>,
Martin Radev <martin.b.radev@gmail.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 2/5] x86/boot/compressed/64: Add CPUID sanity check to early #VC handler
Date: Wed, 28 Oct 2020 12:15:27 -0500 [thread overview]
Message-ID: <ca27f626-2a9e-09e6-a2aa-a4acbc51929c@amd.com> (raw)
In-Reply-To: <20201028164659.27002-3-joro@8bytes.org>
On 10/28/20 11:46 AM, Joerg Roedel wrote:
> From: Joerg Roedel <jroedel@suse.de>
>
> The early #VC handler which doesn't have a GHCB can only handle CPUID
> exit codes. It is needed by the early boot code to handle #VC
> exceptions raised in verify_cpu() and to get the position of the C
> bit.
>
> But the CPUID information comes from the hypervisor, which is untrusted
> and might return results which trick the guest into the no-SEV boot path
> with no C bit set in the page-tables. All data written to memory would
> then be unencrypted and could leak sensitive data to the hypervisor.
>
> Add sanity checks to the early #VC handlers to make sure the hypervisor
> can not pretend that SEV is disabled.
>
> Signed-off-by: Joerg Roedel <jroedel@suse.de>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
> ---
> arch/x86/kernel/sev-es-shared.c | 26 ++++++++++++++++++++++++++
> 1 file changed, 26 insertions(+)
>
> diff --git a/arch/x86/kernel/sev-es-shared.c b/arch/x86/kernel/sev-es-shared.c
> index 5f83ccaab877..56d16c405b03 100644
> --- a/arch/x86/kernel/sev-es-shared.c
> +++ b/arch/x86/kernel/sev-es-shared.c
> @@ -178,6 +178,32 @@ void __init do_vc_no_ghcb(struct pt_regs *regs, unsigned long exit_code)
> goto fail;
> regs->dx = val >> 32;
>
> + /*
> + * This is a VC handler and the #VC is only raised when SEV-ES is
> + * active, which means SEV must be active too. Do sanity checks on the
> + * CPUID results to make sure the hypervisor does not trick the kernel
> + * into the no-sev path. This could map sensitive data unencrypted and
> + * make it accessible to the hypervisor.
> + *
> + * In particular, check for:
> + * - Hypervisor CPUID bit
> + * - Availability of CPUID leaf 0x8000001f
> + * - SEV CPUID bit.
> + *
> + * The hypervisor might still report the wrong C-bit position, but this
> + * can't be checked here.
> + */
> +
> + if ((fn == 1 && !(regs->cx & BIT(31))))
> + /* Hypervisor bit */
> + goto fail;
> + else if (fn == 0x80000000 && (regs->ax < 0x8000001f))
> + /* SEV Leaf check */
> + goto fail;
> + else if ((fn == 0x8000001f && !(regs->ax & BIT(1))))
> + /* SEV Bit */
> + goto fail;
> +
> /* Skip over the CPUID two-byte opcode */
> regs->ip += 2;
>
>
next prev parent reply other threads:[~2020-10-28 21:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-28 16:46 [PATCH v4 0/5] x86/sev-es: Mitigate some HV attack vectors Joerg Roedel
2020-10-28 16:46 ` [PATCH v4 1/5] x86/boot/compressed/64: Introduce sev_status Joerg Roedel
2020-10-28 17:14 ` Tom Lendacky
2020-10-29 19:17 ` [tip: x86/seves] " tip-bot2 for Joerg Roedel
2020-10-28 16:46 ` [PATCH v4 2/5] x86/boot/compressed/64: Add CPUID sanity check to early #VC handler Joerg Roedel
2020-10-28 17:15 ` Tom Lendacky [this message]
2020-10-29 19:17 ` [tip: x86/seves] x86/boot/compressed/64: Sanity-check CPUID results in the " tip-bot2 for Joerg Roedel
2020-10-28 16:46 ` [PATCH v4 3/5] x86/boot/compressed/64: Check SEV encryption in 64-bit boot-path Joerg Roedel
2020-10-28 17:25 ` Tom Lendacky
2020-10-29 19:17 ` [tip: x86/seves] " tip-bot2 for Joerg Roedel
2020-10-28 16:46 ` [PATCH v4 4/5] x86/head/64: Check SEV encryption before switching to kernel page-table Joerg Roedel
2020-10-28 17:29 ` Tom Lendacky
2020-10-29 19:17 ` [tip: x86/seves] " tip-bot2 for Joerg Roedel
2020-10-28 16:46 ` [PATCH v4 5/5] x86/sev-es: Do not support MMIO to/from encrypted memory Joerg Roedel
2020-10-28 17:31 ` Tom Lendacky
2020-10-29 19:17 ` [tip: x86/seves] " tip-bot2 for Joerg Roedel
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-all 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=ca27f626-2a9e-09e6-a2aa-a4acbc51929c@amd.com \
--to=thomas.lendacky@amd.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=joro@8bytes.org \
--cc=jroedel@suse.de \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=martin.b.radev@gmail.com \
--cc=mingo@redhat.com \
--cc=nivedita@alum.mit.edu \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/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