Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3701135ybv; Mon, 10 Feb 2020 04:59:33 -0800 (PST) X-Google-Smtp-Source: APXvYqz/yo30abMcACeD15j3BPMjb3BIt/iWCWxquZBln1CuPpoZxLRjZC+IKyAunyLkKrhn03IE X-Received: by 2002:a05:6830:1e64:: with SMTP id m4mr991847otr.244.1581339573574; Mon, 10 Feb 2020 04:59:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581339573; cv=none; d=google.com; s=arc-20160816; b=u1msTaXwwJQjoIcuwX7jo7qK/JHe8nYix7L3S8G7R0rh94apaL/Q5t2wt+mXDN6M4J Po3EdG3jjEH5XMOYGGWCWhqrgQJESpIIhpwpbY8KssEukyf4UIyy+qE0AJi6ER766qCC HZsE7qwXYfb8VJRvTIVPDY3sVGk+gCxF1xeUbQ6jkExTbkOmaAxQ9tcqCKF1fO9sJMjB a6VI2F2/5LtdS4d4ZLavZwx9Z+A42aNm2FfWGjQMTQSjkqPM92Aznr2EuA1W9sGOemB6 I6Ds0xLWD/wJYoRL452xlCKUvaN3qdmtM58/46y5oRCwbF0p2aa3RIbad/ladU+GaRL1 7Yww== 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=IMhva0YMR6YXEk39azq7c9eDNATuq3haVu5AVgbal+8=; b=PjcdlQCUk6kvLIU8bn/jTrfkiC1wKHOnDPkYcPErL8h+1eQEovEVwnrvfb8a/ItAJW lz0AoWGn/jR/TM0QFNUuseABQkZEq6RRSA7x8XpjENPcbffiDGn5meeuYhhCLCiElYv1 G0jwU9AafHdGCUQKK8UVkqc8fLWtQulD40+lIUOkwdaxnGKRSus9gOqhx9cC7KM/DvaY cIgG39fS8dAVeVtED7HpI4PHmlwaUS9A0jj2Q3AyKx01t64G01gZdruBPcOJtvBf1AWM k6KKNf8gd/2/q4IQPdfJlXZ1GF9K1sTSmfa8HGK8Y1RlZuD9ikwFUVWvUDf32MBLfoYG AsNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CKyWhmAX; 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 l131si126323oig.120.2020.02.10.04.59.21; Mon, 10 Feb 2020 04:59:33 -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=CKyWhmAX; 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 S1730019AbgBJM7T (ORCPT + 99 others); Mon, 10 Feb 2020 07:59:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:42896 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729237AbgBJMlL (ORCPT ); Mon, 10 Feb 2020 07:41:11 -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 532A620733; Mon, 10 Feb 2020 12:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338471; bh=qR8NXDPCQMI8FGPV19d0pW79RHVbnYIvHzvQJh07a0Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CKyWhmAX1ik6asdzcD70wK5CNHYQ4KcM2oAD26LWa6hOeqSQSECJHq4ispYTsxe3b e+bMH1BWCweTn7Fgvuv+M/jaXWiVfrqT089zZZuutDMfCTI6ZhelABHuFzy3Z38x+r YOSoSH8GkJArrzg2rmqqcbpK4cFl1jjGG8TSJwJM= 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 236/367] KVM: x86: Protect MSR-based index computations from Spectre-v1/L1TF attacks in x86.c Date: Mon, 10 Feb 2020 04:32:29 -0800 Message-Id: <20200210122445.979512283@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 6ec4c5eee1750d5d17951c4e1960d953376a0dda upstream. This fixes a Spectre-v1/L1TF vulnerability in set_msr_mce() and get_msr_mce(). Both functions contain index computations based on the (attacker-controlled) MSR number. Fixes: 890ca9aefa78 ("KVM: Add MCE support") 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/x86.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2489,7 +2489,10 @@ static int set_msr_mce(struct kvm_vcpu * default: if (msr >= MSR_IA32_MC0_CTL && msr < MSR_IA32_MCx_CTL(bank_num)) { - u32 offset = msr - MSR_IA32_MC0_CTL; + u32 offset = array_index_nospec( + msr - MSR_IA32_MC0_CTL, + MSR_IA32_MCx_CTL(bank_num) - MSR_IA32_MC0_CTL); + /* only 0 or all 1s can be written to IA32_MCi_CTL * some Linux kernels though clear bit 10 in bank 4 to * workaround a BIOS/GART TBL issue on AMD K8s, ignore @@ -2930,7 +2933,10 @@ static int get_msr_mce(struct kvm_vcpu * default: if (msr >= MSR_IA32_MC0_CTL && msr < MSR_IA32_MCx_CTL(bank_num)) { - u32 offset = msr - MSR_IA32_MC0_CTL; + u32 offset = array_index_nospec( + msr - MSR_IA32_MC0_CTL, + MSR_IA32_MCx_CTL(bank_num) - MSR_IA32_MC0_CTL); + data = vcpu->arch.mce_banks[offset]; break; }