Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2962395pxj; Mon, 17 May 2021 14:14:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTswPRKVDYRgi8X2hZzfh6EZtEeHvh9qx2PBEy+qWsCDlW7V66a210piIeiaippbeFwPYo X-Received: by 2002:a17:907:1749:: with SMTP id lf9mr2023162ejc.178.1621286043317; Mon, 17 May 2021 14:14:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621286043; cv=none; d=google.com; s=arc-20160816; b=kP4Hkq/sQve3U1bHD+TWNK5cX66ZeBMckbx+xFvE+RpcLmZsGti09/y1W5FLAfgsiH 8jIEl6zMGpX+t8fAyWmvBbojqQglH+wr/5Lz6bUCrxB7H7N536yuhJXGDJjN/UskLAWQ K0YfrZfmM8VqyBihoPNL6nfvlJXHlTz0Ste0c3C5eETLu4jbiHWYHr/rW3qnp9wETrCn /FIBteDVdosBWAPQgBDL0+xdjN66IwKv+bx65jpJ5ZodPV7O8OT5RL/TK7sq/lC32zie 9IBQMRMkKCxp7orMLe5Z3HjTxWitQiudhBMfku2d3H5UffdIDXWRo9qZgYlz6Cc97wQs MCPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xBqkozZIxj8Kwzv8m4x15PH5ng0IRJMZLq6RYeI2r7c=; b=HYKALnqChvbKyb7/mtuiJ1bTkIAtno7uWccc4ggu5P5sMif4ZvJVNp5ynj1K1q1oin IlCtg2CtNzdHLSXBgmz85IuuSTQqx41xwAxMFgA6n5ogl6H86JH2Ol8O2gLsdEycOMLO VSu6nKZt2KZl7WSnuEuEicKigXsw7f6uz6CT/jOM9qXOxNVMmFwhfCBKZ7wGTzRcsSXt SkwAV/uDSo39o/MJvGtg03NMoSWf7pmk/hnJFSabw3Vr9OzBn99QStEcYRV1N/kZ6Mm4 8VJaWiufPU1zJkUmEJGLprvoFqgNB7Uhe6QiQFy5o1ImcyHr+Q8Pzejrgt0x69O1kMAK mA0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=t+n5J5br; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bh7si15342460ejb.383.2021.05.17.14.13.39; Mon, 17 May 2021 14:14:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=t+n5J5br; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238139AbhEQOIW (ORCPT + 99 others); Mon, 17 May 2021 10:08:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:59648 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237788AbhEQOGw (ORCPT ); Mon, 17 May 2021 10:06:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DEC6C613B6; Mon, 17 May 2021 14:05:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260319; bh=rK0r5Ef8i/Z9uL9O4pNrJSPaZ3ToAPS5p62LI0Lwyp4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t+n5J5brcSMBZYFTibpZnOqICBNy7o2A4tssyYlCSou/s0gKG1kMnalg4l4NyrNAX R19RZeDL0o4WGN9QrUIQLgda4rLTU7unmcMKEXALN3yvQu9RsP+nApOsKVIMmEDX8c wYvlk7NLgSpEoY8RR26nbYjIy8g1E+TjJ2EieMCU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tom Lendacky , Paolo Bonzini Subject: [PATCH 5.12 006/363] KVM: SVM: Make sure GHCB is mapped before updating Date: Mon, 17 May 2021 15:57:52 +0200 Message-Id: <20210517140302.746031602@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tom Lendacky commit a3ba26ecfb569f4aa3f867e80c02aa65f20aadad upstream. Access to the GHCB is mainly in the VMGEXIT path and it is known that the GHCB will be mapped. But there are two paths where it is possible the GHCB might not be mapped. The sev_vcpu_deliver_sipi_vector() routine will update the GHCB to inform the caller of the AP Reset Hold NAE event that a SIPI has been delivered. However, if a SIPI is performed without a corresponding AP Reset Hold, then the GHCB might not be mapped (depending on the previous VMEXIT), which will result in a NULL pointer dereference. The svm_complete_emulated_msr() routine will update the GHCB to inform the caller of a RDMSR/WRMSR operation about any errors. While it is likely that the GHCB will be mapped in this situation, add a safe guard in this path to be certain a NULL pointer dereference is not encountered. Fixes: f1c6366e3043 ("KVM: SVM: Add required changes to support intercepts under SEV-ES") Fixes: 647daca25d24 ("KVM: SVM: Add support for booting APs in an SEV-ES guest") Signed-off-by: Tom Lendacky Cc: stable@vger.kernel.org Message-Id: Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/svm/sev.c | 3 +++ arch/x86/kvm/svm/svm.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2106,5 +2106,8 @@ void sev_vcpu_deliver_sipi_vector(struct * the guest will set the CS and RIP. Set SW_EXIT_INFO_2 to a * non-zero value. */ + if (!svm->ghcb) + return; + ghcb_set_sw_exit_info_2(svm->ghcb, 1); } --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2811,7 +2811,7 @@ static int svm_get_msr(struct kvm_vcpu * static int svm_complete_emulated_msr(struct kvm_vcpu *vcpu, int err) { struct vcpu_svm *svm = to_svm(vcpu); - if (!sev_es_guest(svm->vcpu.kvm) || !err) + if (!err || !sev_es_guest(vcpu->kvm) || WARN_ON_ONCE(!svm->ghcb)) return kvm_complete_insn_gp(&svm->vcpu, err); ghcb_set_sw_exit_info_1(svm->ghcb, 1);