From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6008FC55179 for ; Thu, 29 Oct 2020 19:18:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0015A20782 for ; Thu, 29 Oct 2020 19:18:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wJ5nD3in"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="l6idq2h6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726127AbgJ2TSe (ORCPT ); Thu, 29 Oct 2020 15:18:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725932AbgJ2TRo (ORCPT ); Thu, 29 Oct 2020 15:17:44 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35698C0613CF; Thu, 29 Oct 2020 12:17:44 -0700 (PDT) Date: Thu, 29 Oct 2020 19:17:41 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1603999062; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OlWtMMkpruve3YAQ6Lkk3FveNKTzsoC/56ay9Ftkrb8=; b=wJ5nD3inaHnapF7kxWu9z2AojMSXv7HAEhA853V9/R4Rbp06M7NKQIrLvl3uv9QJT1ojUI o8HnuAx8VLUkvha5+7buA4VDVW6EjqtYveSB+wZo6oy87aKlpvI3SZPcQKQotHjdcXdScL whxLXDPuK+QCczyDLlGZczY/Cc8VV4DoouffPch2qNnjBMFhBjp9WvJtI2Zu2RJIZkYpCZ duzRDoqltTXV1tmhGhur/Swcn1sj10FznIAczcFVtS5sl5X1MK+cTKsuyIFIfCx3ELjKVg 2ANjfNsUcakRw5jIvlViXISa0GkOKXZe4zbhcH9buxHcHZJKyXUw88HMokQgHw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1603999062; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OlWtMMkpruve3YAQ6Lkk3FveNKTzsoC/56ay9Ftkrb8=; b=l6idq2h65kZh6Bn9fpYGmQ2BtvJjNHdec/wLrY+5GhYczXQwNnNVzOnjj7b3jsFY3E/wEo 5eDSNNMPYfRoQXDQ== From: "tip-bot2 for Joerg Roedel" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/seves] x86/boot/compressed/64: Sanity-check CPUID results in the early #VC handler Cc: Joerg Roedel , Borislav Petkov , Tom Lendacky , x86 , LKML In-Reply-To: <20201028164659.27002-3-joro@8bytes.org> References: <20201028164659.27002-3-joro@8bytes.org> MIME-Version: 1.0 Message-ID: <160399906180.397.10854980565108573862.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/seves branch of tip: Commit-ID: ed7b895f3efb5df184722f5a30f8164fcaffceb1 Gitweb: https://git.kernel.org/tip/ed7b895f3efb5df184722f5a30f8164fcaffceb1 Author: Joerg Roedel AuthorDate: Wed, 28 Oct 2020 17:46:56 +01:00 Committer: Borislav Petkov CommitterDate: Thu, 29 Oct 2020 13:48:49 +01:00 x86/boot/compressed/64: Sanity-check CPUID results in the early #VC handler 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 handler to make sure the hypervisor can not pretend that SEV is disabled. [ bp: Massage a bit. ] Signed-off-by: Joerg Roedel Signed-off-by: Borislav Petkov Reviewed-by: Tom Lendacky Link: https://lkml.kernel.org/r/20201028164659.27002-3-joro@8bytes.org --- 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 5f83cca..7d04b35 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;