From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PATCH] KVM: x86: restrict maximal physical address Date: Fri, 25 Nov 2016 15:51:05 +0100 Message-ID: <20161125145105.9508-1-rkrcmar@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Return-path: Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org The guest could have configured a maximal physical address that exceeds the host. Prevent that situation as it could easily lead to a bug. Signed-off-by: Radim Krčmář --- arch/x86/kvm/cpuid.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 25f0f15fab1a..aed910e9fbed 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -136,7 +136,13 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu) ((best->eax & 0xff00) >> 8) != 0) return -EINVAL; - /* Update physical-address width */ + + /* + * Update physical-address width. + * Make sure that it does not exceed hardware capabilities. + */ + if (cpuid_query_maxphyaddr(vcpu) > boot_cpu_data.x86_phys_bits) + return -EINVAL; vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu); kvm_pmu_refresh(vcpu); -- 2.10.2