Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp861149imm; Fri, 29 Jun 2018 07:35:06 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfx3PAM1cJWbJgMD2mjZt1M3NjhRxf+qXKBk/d7ppj/VSXeDTNS0uC2FVJJ5Hbkc7MHCQjb X-Received: by 2002:a62:3d86:: with SMTP id x6-v6mr1298354pfj.192.1530282906723; Fri, 29 Jun 2018 07:35:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530282906; cv=none; d=google.com; s=arc-20160816; b=r09Qp2BPXLj7ydOTqQ0vHdWQQaQtwLN0yrzqrgUb3y6mwkKSszv/MZsdf5Clu1ntkB MIbtRaR8aNqIBEoedNR8OHCVh1RneO0KpT4OdbzrsRfYbXCtvttpEfw/6U21UUYRP3D1 GnyNdi52Fz9NkKNyUnqyF6rc4QFybS+LIrabQtOPtHREoSz2sHHTc6B4hqUbjiTqUSJa P1faZfOb4TEfhY6wSGxkQUk1PHUrYFfBq2xPxTnf+dMGzLJKL9pOS7sIUgEcO510QX0a m6KSL0JnLlhhQVpp/h9Sr9t6Y4uvUP1aXhpeCHfJyRnt7kVaMSeEYi2mN7tELSlKvZt/ ez2w== 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=uIEn8VXl6ejA0QBOMhiyTWzFdGKt/cjdfAWNTTZfETA=; b=XYgoLxRA/Ds2lvViDaFK5GZuWGIUhOM1Y0sqxhntMCaL1jPagP3Bazz4Z2PGLd8ioA L2n8xPv60T6KveGnTEudbnZoZxyaY73tOgNlUDZvicilG/4Jfar4ZlL7eYyjhrifjuJz IlSq5hdxNvAvsV66q9oQkv0dRjclW5g2y/0+rk3EXFmaw8PxYVoPSsFQ2UuZYtF/rNGp xf2SxZM/i7nn9/zNWifQDOPw9aJMgB7QGlpP2Gj05NmqyL2Mha5C7qRhLNZXOxFfAnTA rj2hfTxpCnq0FqnEVQQMn7Ega4Tc/ESgUZlM5nfdn1tFwPtwkpJkh0LZyqZL9HeTbdLJ z7Sw== 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 o18-v6si5093141pgg.250.2018.06.29.07.34.52; Fri, 29 Jun 2018 07:35:06 -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 S1755594AbeF2OPE (ORCPT + 99 others); Fri, 29 Jun 2018 10:15:04 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57104 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754825AbeF2OPB (ORCPT ); Fri, 29 Jun 2018 10:15:01 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5229C401DED4; Fri, 29 Jun 2018 14:15:01 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 56B1F1102E29; Fri, 29 Jun 2018 14:14:59 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org Cc: x86@kernel.org, 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 v3 1/5] KVM: x86: hyperv: enforce vp_index < KVM_MAX_VCPUS Date: Fri, 29 Jun 2018 16:14:51 +0200 Message-Id: <20180629141455.19525-2-vkuznets@redhat.com> In-Reply-To: <20180629141455.19525-1-vkuznets@redhat.com> References: <20180629141455.19525-1-vkuznets@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 29 Jun 2018 14:15:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 29 Jun 2018 14:15:01 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 --- 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 af8caf965baa..ceaa7fb10c49 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) @@ -1038,7 +1040,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