Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1005720imm; Wed, 26 Sep 2018 10:04:23 -0700 (PDT) X-Google-Smtp-Source: ACcGV61wgXX9r1dWpXIdVMP4aabRhzVNGLacLQjjUfXg/yP8iL7JfbDNGKrNMvHw81QmoJiLbNq5 X-Received: by 2002:a63:e60c:: with SMTP id g12-v6mr6613245pgh.308.1537981463925; Wed, 26 Sep 2018 10:04:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537981463; cv=none; d=google.com; s=arc-20160816; b=kKBZSFVjZKX+NXcsfVhIep1mFusoGrYmKrhcWIzJMOAOVlHcChZ6MDb4M+DsiVbiC7 IMrdY1fAYEPSMXn6KM2MM0z5bXil97LFSP7FZPhuA6+8dtaxfTTZ8JYKtkAdDotiX5ll zE+uum94aWKjeycsLvjEG9JDCsrUVU1P1yZf0mEWGPLgTdqEwxnmIqzybcXkWtrl9679 4e5jeV0B+LouJkzlMWFh4YdkOFSDlTfOu9IiFcrrcLdTO1N/ajFlkn2hMCTE8pVKCgsM i1zrC3ayzTIGbBRQqAdJ5Wl8Wxx/lavAP89lzKn91Od0REUXy7W7XM7MjSgqVlcPzpji +XPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=vg//kOaDcUz0UvBUUC+NGVxkH0guTdzKHIJT/MHB4OM=; b=PrF9QYfducQXMOxOeFW11McWhaGxAiHbft0Vn01J9RIEk809jRpYNaKDI2kiknHWAK h/JTPjvXtDyMDlTGTcygdTDpNEu2OPOoHnbHHogH7NOfnXkixxm5+6nBc0pCfw0JN8E1 dQKNAOzRKySIxyE0RZUr1/OFZhxzkp0vEl6fKNOrbZo+xy5So2KUkuNuZ5lhq10bOVNf akjRgdo/sryZCOputMxy453j3KOli9eg8N+wJ2A40XzY5f7XzuxYbWLEBBYO7D92uyoC esu7OYhGPzf/lxwSt6ABRzCwiCA0p4EPW58uP05NIY8l1AB0ycF9vtubRfRerXe8QvbN 3l1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s16-v6si4870131plq.377.2018.09.26.10.04.08; Wed, 26 Sep 2018 10:04:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728675AbeIZXRA (ORCPT + 99 others); Wed, 26 Sep 2018 19:17:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60893 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728642AbeIZXQ7 (ORCPT ); Wed, 26 Sep 2018 19:16:59 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AFEB6307D910; Wed, 26 Sep 2018 17:03:06 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.217]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24E1060BE7; Wed, 26 Sep 2018 17:03:03 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Roman Kagan , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , "Michael Kelley (EOSG)" , Mohammed Gamal , Cathy Avery , Wanpeng Li , linux-kernel@vger.kernel.org Subject: [PATCH v6 1/7] KVM: x86: hyperv: enforce vp_index < KVM_MAX_VCPUS Date: Wed, 26 Sep 2018 19:02:53 +0200 Message-Id: <20180926170259.29796-2-vkuznets@redhat.com> In-Reply-To: <20180926170259.29796-1-vkuznets@redhat.com> References: <20180926170259.29796-1-vkuznets@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 26 Sep 2018 17:03:06 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hyper-V TLFS (5.0b) states: > Virtual processors are identified by using an index (VP index). The > maximum number of virtual processors per partition supported by the > current implementation of the hypervisor can be obtained through CPUID > leaf 0x40000005. A virtual processor index must be less than the > maximum number of virtual processors per partition. Forbid userspace to set VP_INDEX above KVM_MAX_VCPUS. get_vcpu_by_vpidx() can now be optimized to bail early when supplied vpidx is >= KVM_MAX_VCPUS. Signed-off-by: Vitaly Kuznetsov Reviewed-by: Roman Kagan --- arch/x86/kvm/hyperv.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 01d209ab5481..0cd597b0f754 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -132,8 +132,10 @@ static struct kvm_vcpu *get_vcpu_by_vpidx(struct kvm *kvm, u32 vpidx) struct kvm_vcpu *vcpu = NULL; int i; - if (vpidx < KVM_MAX_VCPUS) - vcpu = kvm_get_vcpu(kvm, vpidx); + if (vpidx >= KVM_MAX_VCPUS) + return NULL; + + vcpu = kvm_get_vcpu(kvm, vpidx); if (vcpu && vcpu_to_hv_vcpu(vcpu)->vp_index == vpidx) return vcpu; kvm_for_each_vcpu(i, vcpu, kvm) @@ -1044,7 +1046,7 @@ static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host) switch (msr) { case HV_X64_MSR_VP_INDEX: - if (!host) + if (!host || (u32)data >= KVM_MAX_VCPUS) return 1; hv->vp_index = (u32)data; break; -- 2.17.1