Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp698067ybv; Thu, 13 Feb 2020 07:58:14 -0800 (PST) X-Google-Smtp-Source: APXvYqxCgLAxQG33QnbdBe6abwGeRAYtI3ANw9AHBpvNSWshcJTwHlBpjo/0TUFxrKFLPg+QgrYv X-Received: by 2002:a05:6808:7dd:: with SMTP id f29mr3437518oij.67.1581609494790; Thu, 13 Feb 2020 07:58:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581609494; cv=none; d=google.com; s=arc-20160816; b=tFLQgeSQlZ/b3zVWMBBtR8N0EQ1C+sQLREM828KK+oQswxfw2ILik3N7F3ZiGoqR68 GUUsRyKnDbD206xTu+Mlp1WeDo/HGKrwPFODjE0gzaOKVQumfuG6z359H+SwK/g5Jxo7 8OXaHS7XAr2WYMClb9oI9Yurn3RzERkfeQc6Td5oOCtJkduHkOFr4K9NDYtsU18I1Cmy wsQhOd/QD5Ho5T7dasIGLIx9Y1XWvtQgwQqLmdznskqQUsqlyAZouBiKkGH9/7By9H8/ L4Pq8xc03krO0UKbXcSRuMj65Ry6suxf/tT9aiwtvO4AYBNayR+izBZyCGBWMIHOCiU9 PWjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ckAWoiY11UuORz6zd4PdTcEcgEF4LAegJ2Jwttb5TUQ=; b=bYIf1HxZbo5R31CWMYYg3IJVrjfpujsBl2931W1v/zEXu+Y4wG3XOJc9ExVZdPcKfl OMzHBAtM5h091LSN/8Uv5xvmsWGNi7G3f5rL4e4yFZ4uEU45LS+IJkX6o20TJTWfT7/R FzDFtftpA61ALvrcN03fM+786B1TrSETxfj5xTgTdt6Pbxkq+PveTzAzPK8+nRdWxzUe jxwN13ERkyurvdXqxW4T4yvNRnHQP/JuqdMSEqdMmBHxuMOu2OBJmMIBD0XiJD1kujO5 2S/y3kMeO2JqAvvBVy5ogdfR1AdqHjQW8B1VdvzPOdGfwXDuumpbc7W/cKS+xGfMDhls JDdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2QgPY017; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i194si1378830oib.73.2020.02.13.07.58.02; Thu, 13 Feb 2020 07:58:14 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=2QgPY017; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728953AbgBMPZO (ORCPT + 99 others); Thu, 13 Feb 2020 10:25:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:35428 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727964AbgBMPXm (ORCPT ); Thu, 13 Feb 2020 10:23:42 -0500 Received: from localhost (unknown [104.132.1.104]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 56766246B1; Thu, 13 Feb 2020 15:23:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581607421; bh=KrcVLInCN6Z6I+BQc3e5clvvexlfxB1Z7e9YlM3aRaQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2QgPY017yJedAHVGOa8y9ef1aq6LbYK75vKPRc1v8VbWjJSgJrgk1dVj8O1XLFCOH 2sjkSB9q/vG9p03e2GvVrvIKm55i3mXD2ibh6KVM25HscFHaEzmI5RTitGMRZA0XTC 6AovM7jBmYwZt2N4rw/JGHI8c8kzlQ6JYqZNoKGM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nick Finco , Marios Pomonis , Andrew Honig , Jim Mattson , Paolo Bonzini Subject: [PATCH 4.9 049/116] KVM: x86: Protect MSR-based index computations in pmu.h from Spectre-v1/L1TF attacks Date: Thu, 13 Feb 2020 07:19:53 -0800 Message-Id: <20200213151901.759623681@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200213151842.259660170@linuxfoundation.org> References: <20200213151842.259660170@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marios Pomonis commit 13c5183a4e643cc2b03a22d0e582c8e17bb7457d upstream. This fixes a Spectre-v1/L1TF vulnerability in the get_gp_pmc() and get_fixed_pmc() functions. They both contain index computations based on the (attacker-controlled) MSR number. Fixes: 25462f7f5295 ("KVM: x86/vPMU: Define kvm_pmu_ops to support vPMU function dispatch") Signed-off-by: Nick Finco Signed-off-by: Marios Pomonis Reviewed-by: Andrew Honig Cc: stable@vger.kernel.org Reviewed-by: Jim Mattson Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/pmu.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) --- a/arch/x86/kvm/pmu.h +++ b/arch/x86/kvm/pmu.h @@ -1,6 +1,8 @@ #ifndef __KVM_X86_PMU_H #define __KVM_X86_PMU_H +#include + #define vcpu_to_pmu(vcpu) (&(vcpu)->arch.pmu) #define pmu_to_vcpu(pmu) (container_of((pmu), struct kvm_vcpu, arch.pmu)) #define pmc_to_pmu(pmc) (&(pmc)->vcpu->arch.pmu) @@ -80,8 +82,12 @@ static inline bool pmc_is_enabled(struct static inline struct kvm_pmc *get_gp_pmc(struct kvm_pmu *pmu, u32 msr, u32 base) { - if (msr >= base && msr < base + pmu->nr_arch_gp_counters) - return &pmu->gp_counters[msr - base]; + if (msr >= base && msr < base + pmu->nr_arch_gp_counters) { + u32 index = array_index_nospec(msr - base, + pmu->nr_arch_gp_counters); + + return &pmu->gp_counters[index]; + } return NULL; } @@ -91,8 +97,12 @@ static inline struct kvm_pmc *get_fixed_ { int base = MSR_CORE_PERF_FIXED_CTR0; - if (msr >= base && msr < base + pmu->nr_arch_fixed_counters) - return &pmu->fixed_counters[msr - base]; + if (msr >= base && msr < base + pmu->nr_arch_fixed_counters) { + u32 index = array_index_nospec(msr - base, + pmu->nr_arch_fixed_counters); + + return &pmu->fixed_counters[index]; + } return NULL; }