Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp246827pxb; Fri, 3 Sep 2021 00:57:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLZraotlji8ottGGFAyQxH9Gr0bMycisStwqtp0afVfHtP1EOgIA/WeEq9XUGF4gkUnreH X-Received: by 2002:a05:6e02:214e:: with SMTP id d14mr1718223ilv.142.1630655854262; Fri, 03 Sep 2021 00:57:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630655854; cv=none; d=google.com; s=arc-20160816; b=bFjeoIRI1WkZ74iT05dpQlFDGpn6MY8SdKmMoHaBFNR/Ye9zzP9DsF7y7x5XUp4xps aInO7Q0Sb+Kv5hVP8IQLDsBwWaaQD7EYZWzekz8yEdrODMZ7i4lq+N6GRRRQqbcLxBkW G7eB7eA6EDgtpYtpzxBUMoepFv5qLtnYU/KR8J892nXSmDWFR6ysetKYrPZES43FwWkh YLBY5GgWvuduT+aY9nUo63j/XtGSrZUJTq8oNWoQkOluBR+yU/Jze8Xev8PD8tkQMGYt qUTdq0pZ/OqWWl4IReFejVMtzm31P5bgvDJJKy/RafOpfOI+qlSrW0/ZDyn+KWa4zaxq yQJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=ExbPk+2hilK1PF5+HxeSYcDfJh6DAFTTX6ZBQtPlWWs=; b=EFB+AZpig2KjVL4L9xY2nXrxyrzeSScsYUTGCqaFIy57Z2GyFQnjsZQpbbuMJ7TMiK A9p3uV9tenCNLkNI59Snxjo7mE97MZnO5MLTtYO3A6yfHkiAa16ZIcUwHBZOF4OL2B9L l0BMjgfIUc+KvmxM8lD0MCm16an+3XTdHUjoZs5orcJQq+uzFmx3rU7ZwwJLMlW1rMKI Np2g/EfCwOqPxHTpI4+uNxQuJGQ/m6ylUMZ0gE1v+lN/KfDxSPakocmEJKBZji6qX+iX Mkg8aAK2cG2ydOv51UKrIyeFs45PFtHcLWS9iyxCU46ILxQmSj1dH7Syxpfw4Vnrjj+H luEA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a21si3986932iot.52.2021.09.03.00.57.22; Fri, 03 Sep 2021 00:57:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348069AbhICH4o (ORCPT + 99 others); Fri, 3 Sep 2021 03:56:44 -0400 Received: from smtp21.cstnet.cn ([159.226.251.21]:38388 "EHLO cstnet.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1348034AbhICH4n (ORCPT ); Fri, 3 Sep 2021 03:56:43 -0400 Received: from localhost.localdomain (unknown [124.16.138.128]) by APP-01 (Coremail) with SMTP id qwCowABXazDW1DFh9IwiAA--.56360S2; Fri, 03 Sep 2021 15:55:02 +0800 (CST) From: Jiang Jiasheng To: pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, jarkko@kernel.org, dave.hansen@linux.intel.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sgx@vger.kernel.org, Jiang Jiasheng Subject: [PATCH 4/4] KVM: X86: Potential 'index out of range' bug Date: Fri, 3 Sep 2021 07:55:00 +0000 Message-Id: <1630655700-798374-1-git-send-email-jiasheng@iscas.ac.cn>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c7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxh VjvjDU0xZFpf9x0JUvQ6LUUUUU= X-Originating-IP: [124.16.138.128] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The kvm_get_vcpu() will call for the array_index_nospec() with the value of atomic_read(&(v->kvm)->online_vcpus) as size, and the value of constant '0' as index. If the size is also '0', it will be unreasonabe that the index is no less than the size. Signed-off-by: Jiang Jiasheng --- arch/x86/kvm/x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index e0f4a46..c59013c 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2871,7 +2871,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v) offsetof(struct compat_vcpu_info, time)); if (vcpu->xen.vcpu_time_info_set) kvm_setup_pvclock_page(v, &vcpu->xen.vcpu_time_info_cache, 0); - if (v == kvm_get_vcpu(v->kvm, 0)) + if (atomic_read(&(v->kvm)->online_vcpus) > 0 && v == kvm_get_vcpu(v->kvm, 0)) kvm_hv_setup_tsc_page(v->kvm, &vcpu->hv_clock); return 0; } -- 2.7.4