Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp238894imm; Wed, 22 Aug 2018 03:22:30 -0700 (PDT) X-Google-Smtp-Source: ANB0VdamxplW36eY8U8T1iwmBUiCT0yDMNV1Xc7n97rCpuvATcGUdzYwGO/hd5bYAcghNKlG6SZY X-Received: by 2002:a63:444d:: with SMTP id t13-v6mr5508153pgk.102.1534933350084; Wed, 22 Aug 2018 03:22:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534933350; cv=none; d=google.com; s=arc-20160816; b=iiQS97UeYUL+NZGlgxeKAr1PuuhIOlRBBvjwfFCi2QNkiJDJCT7ZaoQfvhtl193Pvu +EQjkx6JTgPIYM2xJhGz2BA9RcRXKa8kjuKQzVGsq64zgZ3GU1jghkvjdxDfGZrRos86 ubbujVdjMKe0wpBIMrZH50PSffTsAH+f3yaSMqH5W1CJg7pOvKFlfjZxXblU5h2NtB1J GUjG4Ku52bjhrUm2yyOMIJUUh0WjoDrxQ6+rPBsdhqpb2yppC0IA77Zbv5gAtD86w2lp Ql+L2T/xcLpM/CBy0LHbCHaptJ0+/omUo62Cv6yM9uXf1CWBQuGIMFYllrlg3hEY6qRf UMQw== 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:arc-authentication-results; bh=sqZLm20pDC+BvEwsCw/pb+7+avL4pinrhSHLXkQ7AKU=; b=Nl7tkI4PFwdW1T6hN11qhph2v7jixnQpoZSIVMfYjwwS+Gxx6k1SH3nECg0mvODWAz n42qabgyi18itPn5Hqfko8f0UtvsSKht/n+uJCYYMfVvT2vZP3E0QiN1hQGXH1U3r0dk RBrRITKbQm4Wv+X+lt8Oks0cKSZuT/twD6nEhrGCQf+gLR4GjPrR0aZrmAiC0Us1mFrI lDC/cIPEe4D17bld8e6qSsgsewJOCHxjYKc1F9wDRBXBW+ciiTYJokQZmLDy8f7sIMw2 NIUWPkRcTZHFaP4SZyCR8WV1KODs2tD40abHjLsKzLjoR/SnYIGHsSJdig2Q9CWemBjP uN1g== 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 l26-v6si1478182pfj.188.2018.08.22.03.22.15; Wed, 22 Aug 2018 03:22:30 -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 S1728658AbeHVNmz (ORCPT + 99 others); Wed, 22 Aug 2018 09:42:55 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52146 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727396AbeHVNmx (ORCPT ); Wed, 22 Aug 2018 09:42:53 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 226258076894; Wed, 22 Aug 2018 10:18:37 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BA4D7D4C9; Wed, 22 Aug 2018 10:18:35 +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)" , Wanpeng Li , linux-kernel@vger.kernel.org Subject: [PATCH v4 RESEND 1/5] KVM: x86: hyperv: enforce vp_index < KVM_MAX_VCPUS Date: Wed, 22 Aug 2018 12:18:28 +0200 Message-Id: <20180822101832.31763-2-vkuznets@redhat.com> In-Reply-To: <20180822101832.31763-1-vkuznets@redhat.com> References: <20180822101832.31763-1-vkuznets@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 22 Aug 2018 10:18:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 22 Aug 2018 10:18:37 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'vkuznets@redhat.com' RCPT:'' 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.14.4