Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3693014ybv; Mon, 10 Feb 2020 04:49:42 -0800 (PST) X-Google-Smtp-Source: APXvYqzwwtaxnu3YQk7TuCJpphoheBYBKHvHouTXvr2zRn1RNPgOlU5yeE+hOp6kLu39fLkTkhKI X-Received: by 2002:a05:6808:45:: with SMTP id v5mr683252oic.90.1581338982373; Mon, 10 Feb 2020 04:49:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581338982; cv=none; d=google.com; s=arc-20160816; b=roS7jbcNLhzQ922CdBib4jTlRnlEP5L12nmVzaFQz+B6Jfjbnt4LeM8r1eQxDAE/Mm jvTbUWalzkuuZaKp/e7PTWIIsxlOew4OqsbzX5U1vRgm8i8MhAevFKPJWO/6Rm1dTadd i6Zekd+gxHEG2BLMWW46GQaG6kK9LCWe6xzKKyynxw/oLivYZU96RE5xB8YeVLEVRTwc Hg3HFhgu6idtMi8exjydccDK3q1W3DL4xG4HQpegnb5fLce/sIk01rWcniEoALvo3/5z tqCPu8UM1/VQ8+UMkFby2dZkodG4aD0josgsTg2K8gwnK71CF1O92eYQ8EdiErOlr8yk JT/A== 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=zNwZKaFiu5zqfwX9x9wrwF/7DsUXkX8gpKbrNfPdkTw=; b=fP0YJqnhDU2zS/w6jP8d8uKeFYqYc+pxZ9qlCuSXvqZQ0+GJkZtoQD3zStD40kvljL 6IwCjJ/OqvwbKZm83AsdX+MOIFv1zTbu2rQ+fa0O6woUPtcxCAmh0rv8w5vAyYuGHu8F 12MO6kAGMjHIkcjmQwyzZjnbFjtdqOCbu14xVWvUkALjsoU/L8pwYC/Wzw8e0N1EO85l czs6iasl+tuZ3rW0lbPNF6TDdMs7Jq3awmjaVT4p94aYPL/a1zZkVwBYt86tSvYTnG6R hoBo2ptKQTmSqN8EObDIcsiMMKyyUXtbRgXNE1Bi5broFFtqSlEtc3QqmkPYMA3m0OzI ieYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vvQNzW1U; 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 m5si120766oie.240.2020.02.10.04.49.30; Mon, 10 Feb 2020 04:49:42 -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=vvQNzW1U; 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 S1730458AbgBJMpx (ORCPT + 99 others); Mon, 10 Feb 2020 07:45:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:42698 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728156AbgBJMlJ (ORCPT ); Mon, 10 Feb 2020 07:41:09 -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 53BF920733; Mon, 10 Feb 2020 12:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338468; bh=XKdpO/y2Hk77eZTPZ2JTfZ3rGi2Q8YTeuWqG9Y6WOhk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vvQNzW1UL0GBR8P66E+yukQBA+Hb0EAWqFb2UXqB/Rsf0x1rXKX+URXfc48HE+qLz k/nn6vuZAQOns7yGpdV+jWNmoXmGAmN3jOnVu6hlxbT4kZXX3p9ToupnDaukpYltKB QYjIkl+h2mSAE2MwLUm7SZmGyYY7GWtgdn83OcJE= 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 231/367] KVM: x86: Protect kvm_lapic_reg_write() from Spectre-v1/L1TF attacks Date: Mon, 10 Feb 2020 04:32:24 -0800 Message-Id: <20200210122445.594617647@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 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 | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1963,15 +1963,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))