Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3690023ybv; Mon, 10 Feb 2020 04:46:15 -0800 (PST) X-Google-Smtp-Source: APXvYqyPQBknwncPPcVZAQ1p15rWbCNCH+2DfSqeRV7fuD48YC/OVZQsmjjUh8utJWFENxuYAEXl X-Received: by 2002:a05:6830:1149:: with SMTP id x9mr966594otq.156.1581338774930; Mon, 10 Feb 2020 04:46:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581338774; cv=none; d=google.com; s=arc-20160816; b=R+Gbta5HAwaIcaJetRUvHD+AaAhaUBWov1PNW7J74jS6OMDMoajThDbZEn1h8qxvp1 tlmfevZL+ilja0eQN5ezi1iJr6ehEbGEu4ofybK/vFWybMO68RIVFgsymBx3LweIObrH N1gofoENk+5q5vqlO2lPnty4PWG3EMP2MZsBFb72GyEoiKrIc46egmnQnaLKLxVIcAC2 A9k0Z3SR0sxFNeqSbrW54O+WYyA9/TSjtPGCyj2+tmIxFu2wXvIjds9vE1azZWUz0MBT eUE913iifLYJOJv3Qkcw1IkvLP1+dOCAB5PZeJq0UmX7VxwoTMH7z4o5HJW5FSORViBb 8l1A== 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=YCAPqwSq8GKdZLTASWiNtKYobwcjiAPgqtRNv2rkLBo=; b=t1EZ6jkrEuD/Vqjp0tMIC6fyJk6Svay9xhqztfuOqyO2FVKtLCgCwfZthTUKF1bWAI 3CzfMZrBaGcZkLoHwIO7xk5Gan1u4MKVv+Hux04MdxH1Xbss0pyg6ChDSqgUINTxHQx4 Rr4O6c1a1w3HAkWG4dIox08XHOQVoR631aV8X6s2QBNy+3XRrxLdehwGhpu8CoQWl5WA V3ZUcIpmpyFgTiWB5oGZ95PHOe90epmZqvNbXVS7UbH6p3pCpYSZhxW+S+l3T0cK0tCb TcHl+HM1HDYrLcd/vfWowcftIjmXcQGf1RzFFbLzYV2I896TW+BIndnUdiAqeEAZ58Kp WQXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MrMmqqAJ; 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 d22si133238oti.316.2020.02.10.04.46.03; Mon, 10 Feb 2020 04:46: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=MrMmqqAJ; 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 S1730648AbgBJMpo (ORCPT + 99 others); Mon, 10 Feb 2020 07:45:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:42486 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729158AbgBJMlG (ORCPT ); Mon, 10 Feb 2020 07:41:06 -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 451CD2080C; Mon, 10 Feb 2020 12:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338466; bh=CSrHh6ckbplG7cDGcTH5GkDJu+ynBZmL5i67RFtgq/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MrMmqqAJn92yI5I6kFOgPKNA306xtSnZvvjp5tY57AR8yemWst35dskEgPLloeSgO dzLopFCMrvYqusyNxyL4nfgsjj2Q9sHEYfq3asm6VGnhnFcQEf0przw+jj1ZfpVKqz BVRwIf+XmM/VQts2Qa4INrMfQKOBAyBu/uwm7gD0= 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 227/367] KVM: x86: Refactor picdev_write() to prevent Spectre-v1/L1TF attacks Date: Mon, 10 Feb 2020 04:32:20 -0800 Message-Id: <20200210122445.362052027@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 14e32321f3606e4b0970200b6e5e47ee6f1e6410 upstream. This fixes a Spectre-v1/L1TF vulnerability in picdev_write(). It replaces index computations based on the (attacked-controlled) port number with constants through a minor refactoring. Fixes: 85f455f7ddbe ("KVM: Add support for in-kernel PIC emulation") 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/i8259.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/arch/x86/kvm/i8259.c +++ b/arch/x86/kvm/i8259.c @@ -460,10 +460,14 @@ static int picdev_write(struct kvm_pic * switch (addr) { case 0x20: case 0x21: + pic_lock(s); + pic_ioport_write(&s->pics[0], addr, data); + pic_unlock(s); + break; case 0xa0: case 0xa1: pic_lock(s); - pic_ioport_write(&s->pics[addr >> 7], addr, data); + pic_ioport_write(&s->pics[1], addr, data); pic_unlock(s); break; case 0x4d0: