Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5060737pxb; Mon, 15 Feb 2021 08:29:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJzIYEkHakmSDGHAV1d8H71CjTp5oCCJelZmSJjU2GGZuBwGZlxxBvEGfK6Iwpa21cmqrTTs X-Received: by 2002:aa7:d857:: with SMTP id f23mr6565767eds.356.1613406573098; Mon, 15 Feb 2021 08:29:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613406573; cv=none; d=google.com; s=arc-20160816; b=NZ70/FXarKbC3EzISC5GZR/R9B70AWRHJ3DZjhpr7nv25MmfPg+uv6YnRFX+2kLkux WTMruiEHU5I8ADRWmMz4gTrS8DtRvE9mtmvYB3Y7RDhmUJPaybPICiYehF7LKOPQSqjf NZDOJ5zKV+LVXzGFelrG/WftNKhyhn03Vj1I5e+zJYhraUexlY4ej6rGcH9fP9YEvmdH M3uozVpSgM01z8od6JqXW0lXXuRcwyPbGvBRPhLmxBTWALpMdScdGwkUd9HvaDX0Orbm tBzy3V1A/ZoAXZOJ2PxcxEvB+KhTKDeUf5vj9t3OUnuXWIK29PzVOYCUkzAaX2/5gBEe oPcQ== 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=ArFQEA72x7Hx9YNtTa4vfezIRerEAcanaBHllwVvrwc=; b=PKHz4/NIHH5N0hz36iQ1bdpXhKsjNulVrwGXDyolcbOGlfaKGNgKKVAJrwN6QNJraL 4K3H4yWkve4VncZgxiOtFzxDDmVYG7Idqo42YD112beW5yrEHOwGpmqaXETEy2oGLiul zZFYJJOohk+MqCHEg+kP4vH3nt8ywx5zqH+tqc1OLGxtkX+8MoEmp79vheWNHnmkzFKn m2NUJZyEtszfbM+ZiPv/0rSRQtZkRVN95JTGKENNzvuzhGhQCvtH9dWPgTaTjivLIdIL ChUmVMIlEqKuMNYUy4ohPP66gH4/4rvt9olilgte6JxenHtFzZDKyqB5dQd+XldUasyZ HmjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NLUymA6R; 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 q17si10094671ejy.390.2021.02.15.08.29.09; Mon, 15 Feb 2021 08:29:33 -0800 (PST) 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=NLUymA6R; 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 S231878AbhBOQ1w (ORCPT + 99 others); Mon, 15 Feb 2021 11:27:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:49598 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231195AbhBOPgz (ORCPT ); Mon, 15 Feb 2021 10:36:55 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id B789E64E95; Mon, 15 Feb 2021 15:32:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613403152; bh=Z6zA4YjEHvL5sTyAuNPMYVZfJqzVp0yb+RJGVduycbs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NLUymA6RPphiTrBUZ4No6ov+3Ao1dcUlSclfW8/EU7VV6vaFxrznnqL4/VNRmOzFH 4EqGtbuZFfZaJ6nYOeTXbn4dz7E6d3fEN3YwRlfFEg7Icjo3XSDYMbC7v9YB+wyrEN N6CB26Nzt1movYWJfYZnTYgxVlkaiPiOWLc0G0lA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.10 048/104] KVM: x86: cleanup CR3 reserved bits checks Date: Mon, 15 Feb 2021 16:27:01 +0100 Message-Id: <20210215152721.031370031@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152719.459796636@linuxfoundation.org> References: <20210215152719.459796636@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: Paolo Bonzini [ Upstream commit c1c35cf78bfab31b8cb455259524395c9e4c7cd6 ] If not in long mode, the low bits of CR3 are reserved but not enforced to be zero, so remove those checks. If in long mode, however, the MBZ bits extend down to the highest physical address bit of the guest, excluding the encryption bit. Make the checks consistent with the above, and match them between nested_vmcb_checks and KVM_SET_SREGS. Cc: stable@vger.kernel.org Fixes: 761e41693465 ("KVM: nSVM: Check that MBZ bits in CR3 and CR4 are not set on vmrun of nested guests") Fixes: a780a3ea6282 ("KVM: X86: Fix reserved bits check for MOV to CR3") Reviewed-by: Sean Christopherson Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- arch/x86/kvm/svm/nested.c | 13 +++---------- arch/x86/kvm/svm/svm.h | 3 --- arch/x86/kvm/x86.c | 2 ++ 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 65e40acde71aa..4fbe190c79159 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -231,6 +231,7 @@ static bool nested_vmcb_check_controls(struct vmcb_control_area *control) static bool nested_vmcb_checks(struct vcpu_svm *svm, struct vmcb *vmcb12) { + struct kvm_vcpu *vcpu = &svm->vcpu; bool vmcb12_lma; if ((vmcb12->save.efer & EFER_SVME) == 0) @@ -244,18 +245,10 @@ static bool nested_vmcb_checks(struct vcpu_svm *svm, struct vmcb *vmcb12) vmcb12_lma = (vmcb12->save.efer & EFER_LME) && (vmcb12->save.cr0 & X86_CR0_PG); - if (!vmcb12_lma) { - if (vmcb12->save.cr4 & X86_CR4_PAE) { - if (vmcb12->save.cr3 & MSR_CR3_LEGACY_PAE_RESERVED_MASK) - return false; - } else { - if (vmcb12->save.cr3 & MSR_CR3_LEGACY_RESERVED_MASK) - return false; - } - } else { + if (vmcb12_lma) { if (!(vmcb12->save.cr4 & X86_CR4_PAE) || !(vmcb12->save.cr0 & X86_CR0_PE) || - (vmcb12->save.cr3 & MSR_CR3_LONG_MBZ_MASK)) + (vmcb12->save.cr3 & vcpu->arch.cr3_lm_rsvd_bits)) return false; } if (kvm_valid_cr4(&svm->vcpu, vmcb12->save.cr4)) diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 1d853fe4c778b..be74e22b82ea7 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -346,9 +346,6 @@ static inline bool gif_set(struct vcpu_svm *svm) } /* svm.c */ -#define MSR_CR3_LEGACY_RESERVED_MASK 0xfe7U -#define MSR_CR3_LEGACY_PAE_RESERVED_MASK 0x7U -#define MSR_CR3_LONG_MBZ_MASK 0xfff0000000000000U #define MSR_INVALID 0xffffffffU u32 svm_msrpm_offset(u32 msr); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 18a315bbcb79e..3bcde449938e6 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9558,6 +9558,8 @@ static int kvm_valid_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) if (!(sregs->cr4 & X86_CR4_PAE) || !(sregs->efer & EFER_LMA)) return -EINVAL; + if (sregs->cr3 & vcpu->arch.cr3_lm_rsvd_bits) + return false; } else { /* * Not in 64-bit mode: EFER.LMA is clear and the code -- 2.27.0