Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3702307ybv; Mon, 10 Feb 2020 05:00:38 -0800 (PST) X-Google-Smtp-Source: APXvYqyoHuwN/QaRBN8BtYRFVD4gh7JSN1r0XGoEIh85LfUAFIBvPmv82SBd1i2PEzxRBHr1DK4e X-Received: by 2002:a05:6808:8ee:: with SMTP id d14mr702937oic.138.1581339638849; Mon, 10 Feb 2020 05:00:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581339638; cv=none; d=google.com; s=arc-20160816; b=eiA49AMs3wyltjNG8AU5E3fIJPnXlzMqtr4CD7AhyzGGhO54fn80uQbw2xGlYG//rl C3F7gJiT3ZWxZ0gKK/fz1gQ3Ju7dPJjpK/5kYNgN1DnAILR9aM2pgIvc2VjhajLP80QY Ugl3/P15dc6b0EHaLsOZOmgd/dDYlEQ51H8cbuaY6XBIhWpwogy3myj9mGdrTiIZleuS cMKDm0BbX08tH2qH6JUY8G0EXsqjVSaTAczILirpECej3IL1Qg0Wzobv9uQiQ6bhubA8 eGcrSavGXbcI73x/MWIhBIkU8BHPbsJnYEZEbaMim6s8P9UpdQozIFjqGpI+cI+akKCc iKlQ== 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=Tp9gsLPCuMf6J3dYFOSTcT5g+uLlKykRAHhVdnGQnqM=; b=Zw7uaOatgY175HLMXvX1dCHW+OimdV5DssuhXRBKVd+vWSAuchNzfx2rg9kCh01HWM X16rwfk0YrYvkCzD9JS+ocVTsdIDn+4gLK2RkG4QXPIlxjtsHQtDstIhIfRurgNTB9Y7 F60S4lgrMNvhbYJMQrC+pvvmfhfzySU7jvnsieD+dKURtf4ww4bxX52RxaTmw5XQTKHN WDauEotExFR/lz7acuia7XkS+acqkKE0IyrVEv9goWwHqHjHEG52kM1Z26fPX3xyu7+7 52nkIdkFPdtGgEB/qIUcUo8IPlNXzN50SrWkMSRxh+k67gSJc8nUfpiT2YvqgU4h2pHu 8djA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bbaNw5e4; 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 x72si138084oia.194.2020.02.10.05.00.27; Mon, 10 Feb 2020 05:00:38 -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=bbaNw5e4; 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 S1730364AbgBJM71 (ORCPT + 99 others); Mon, 10 Feb 2020 07:59:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:42832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729912AbgBJMlK (ORCPT ); Mon, 10 Feb 2020 07:41:10 -0500 Received: from localhost (unknown [209.37.97.194]) (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 520662085B; Mon, 10 Feb 2020 12:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338470; bh=+DsEF5yFpHWnqNpDbdcjQ/e3hDGkvo3VKAOaFXdBIR8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bbaNw5e4hRw8doFq5g78NURmwS49OCVa9yFp+m6Ezc/GMQAUVSS9uWxsXe8uTtB8a HjJradUNWSOe3AWSaWeEyeIyVPElcpvigFj5qy9veVcxDzXqcCmrf51m2HQf5cG2H3 UfDVfX6Z2JdaU6tUxA6tAJQYQsjkKAdze9uyR3/0= 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 5.5 234/367] KVM: x86: Protect MSR-based index computations in pmu.h from Spectre-v1/L1TF attacks Date: Mon, 10 Feb 2020 04:32:27 -0800 Message-Id: <20200210122445.791023940@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@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 @@ -2,6 +2,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) @@ -102,8 +104,12 @@ static inline bool kvm_valid_perf_global 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; } @@ -113,8 +119,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; }