Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp6109515imm; Mon, 27 Aug 2018 09:50:41 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY/E83L9Z+EJj8UALOEVWPZE145INkUhYKkFem+h2QKjjCIyPnVoYRp2z2PKTyTh6Pzv8bZ X-Received: by 2002:a62:d113:: with SMTP id z19-v6mr15076921pfg.98.1535388641355; Mon, 27 Aug 2018 09:50:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535388641; cv=none; d=google.com; s=arc-20160816; b=hwjDAx1rxWWSZO39rO6mwk2gTiAifujGdgxWf/7ZqJjkUz+bV2TlSBe2EE4QS+KFyt 6Ty6AQ2uN29IyGGS0ZJG1UW5kohXSCGB3IjUK2WupNRFXhl8PXgCDR4HOpDE62VHpbyR 8VIVq/NgWKftn8K0pNnaYiElhaQF++g8pVD0Pv8qQjVrpumNREqjiD+LBji71IDvx8gQ +//eK5O/LKAlq0vWvjn2ya42YKdNE9tXLdIICy0UbXCsNhs0FwLYGy+Veoirhspn2gNp JvLdyNdJA6IQgiBQugsHr+thXh4r2IoYcOI6gdNQKPyDtK+i47lMU8OUxG/Z105gdXn6 a7Rg== 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=qzSMgHlIWvlQxP5zKG3GuT9z56JGGaovE/E+bVDzU8mIToqKnqJT8Yr9PyAJroXyuf y8T/r7TSjGBjgNbrTNHjeNZvimAiTCXrGH0PePOxe6CfcuqoHCC6m/zRSq1lvab2mI3o lVw89kT8nt0Qc7mNQhRyXu50Ba5Qifogn2q7mhw9Bl+EUNfXWc4QYaYTTLJftRv7KfI5 R+S+9B0SnQlLacWqVkuNEhPvSIEkeKrQaaY09mnQlK9YEIFUEOTnh3fjGwzP6+D4zydQ IYHPptwhNz6NKiBGz0Kwd9NBi2XdeXzzN1VC/2VepwPAvksEPcI7kdlhnj+gjRlcFnOq cmwQ== 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 w26-v6si15022011pgk.372.2018.08.27.09.50.25; Mon, 27 Aug 2018 09:50:41 -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 S1727388AbeH0Uga (ORCPT + 99 others); Mon, 27 Aug 2018 16:36:30 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33528 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726994AbeH0Ug3 (ORCPT ); Mon, 27 Aug 2018 16:36:29 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3438640201CB; Mon, 27 Aug 2018 16:49:07 +0000 (UTC) Received: from vitty.brq.redhat.com (ovpn-204-86.brq.redhat.com [10.40.204.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id EFF5F2166B41; Mon, 27 Aug 2018 16:49: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 v5 1/5] KVM: x86: hyperv: enforce vp_index < KVM_MAX_VCPUS Date: Mon, 27 Aug 2018 18:48:54 +0200 Message-Id: <20180827164858.12496-2-vkuznets@redhat.com> In-Reply-To: <20180827164858.12496-1-vkuznets@redhat.com> References: <20180827164858.12496-1-vkuznets@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 27 Aug 2018 16:49:07 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 27 Aug 2018 16:49:07 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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