Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp707538ybv; Thu, 13 Feb 2020 08:06:40 -0800 (PST) X-Google-Smtp-Source: APXvYqyq2yzHcPFfMOdpIAImIsYt7SV5SobW13SEQMxr7wBzeVKminnkpA/cDBm25lLQqc9Svxpd X-Received: by 2002:aca:5094:: with SMTP id e142mr3262105oib.101.1581610000654; Thu, 13 Feb 2020 08:06:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581610000; cv=none; d=google.com; s=arc-20160816; b=uzkJ2yjg2Q/ELKf2jFoQfcBDimJij2EonXjrjvQJ+nnhIM56XTzu2UjovwPnBt4AwO PJ3gtiHU75I+++MG2tp+qFmZ84kJ66a4DV4aPBYhCduhia3epapslMF5sGHDQ+/MGpDY KiZwtyA6VcpCtE3HsDNr4TpqFQNwwK9BQ/9OWntzv5moIIbGaoVcQuA3kbB4zPxSd6Mi xKBQXmKBKChrP93iOVn+a+8nNG7PdF5wPnxc37o7aWVZicLWmjrfAOtciWk7H2X8P7Pd Crie+q2Y6wqUuUicKU0WJu46rcIjE+nzAIPDlAfAv+cb1iLfG0eQE/8W95jRvclZMrgM P8JA== 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=XOkWGvNWhKOFIKcZzoyI1kmT+C24HzK+muNJBVjwdD8=; b=j/0HCtok7UAALrzFpwxZNZ1CWFPvlWRrDQcwHbhNGpcr+nljUe9/6xqB/zm+5VfpMJ nuNYU53NiXVSlmBaLkh+07rBLGPGv7GXGFN4iaL1+e2rwAZMAbbMYYTK513B9VbJeyQ5 0hXfc6jZuycSkBAnqIyMF51bTrdcRHK416PnAGdQfq/tQEXppUayUovh1Fs38/pYE/m2 3nKog/Zs6s3HRsRcgc17ROk/ciODkmflJopFFG7WWptYvJU71KKuaFcj9al/9ZvJ3jU4 oBRKF92mIQP/7DdClrxwyyoOYjmwXDsbGhlQn+nRsd4QMkM4o9EUAgvQDfWb4BrYvg4C NI7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=upTipuHe; 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 c144si1448612oig.263.2020.02.13.08.06.24; Thu, 13 Feb 2020 08:06:40 -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=upTipuHe; 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 S1729170AbgBMQFX (ORCPT + 99 others); Thu, 13 Feb 2020 11:05:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:35908 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728504AbgBMPXv (ORCPT ); Thu, 13 Feb 2020 10:23:51 -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 459B3246B1; Thu, 13 Feb 2020 15:23:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581607430; bh=aPRs1KOt/Qo4t2xkXnvnLyTVDxTo1eBGIpfx/JeOrTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=upTipuHeg9LIVU932NCigrjLH0BEStAQRn6RJzr/JOs5Bcm4d3O1p4ALCOPUT7Vpd 9uiRU9wpxeie+IDz2tJN4dFSGXGvBytClLA+3iisIMop1qHH2v9y42xnq8431pu62+ qpGgIfh4g9HaMO6p58gHNyjW/VNKRI7YRjqk6uFw= 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 046/116] KVM: x86: Protect kvm_lapic_reg_write() from Spectre-v1/L1TF attacks Date: Thu, 13 Feb 2020 07:19:50 -0800 Message-Id: <20200213151900.866636406@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 4bf79cb089f6b1c6c632492c0271054ce52ad766 upstream. This fixes a Spectre-v1/L1TF vulnerability in kvm_lapic_reg_write(). This function contains index computations based on the (attacker-controlled) MSR number. Fixes: 0105d1a52640 ("KVM: x2apic interface to lapic") 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/lapic.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -1587,15 +1588,20 @@ int kvm_lapic_reg_write(struct kvm_lapic case APIC_LVTTHMR: case APIC_LVTPC: case APIC_LVT1: - case APIC_LVTERR: + case APIC_LVTERR: { /* TODO: Check vector */ + size_t size; + u32 index; + if (!kvm_apic_sw_enabled(apic)) val |= APIC_LVT_MASKED; - - val &= apic_lvt_mask[(reg - APIC_LVTT) >> 4]; + size = ARRAY_SIZE(apic_lvt_mask); + index = array_index_nospec( + (reg - APIC_LVTT) >> 4, size); + val &= apic_lvt_mask[index]; kvm_lapic_set_reg(apic, reg, val); - break; + } case APIC_LVTT: if (!kvm_apic_sw_enabled(apic))