Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp910245imu; Fri, 11 Jan 2019 11:14:54 -0800 (PST) X-Google-Smtp-Source: ALg8bN45sgtifovBBiL+ob3qKlw+WB5l1ZYthiGcoE8rdHLjxj0YCNjFheGc2gEOQROPVnFt3WQI X-Received: by 2002:a63:160d:: with SMTP id w13mr14830697pgl.43.1547234094109; Fri, 11 Jan 2019 11:14:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547234094; cv=none; d=google.com; s=arc-20160816; b=z+MobaqdmvQiRb+ZXOx5eeeHt2PbTkQ1BDOoJhXLb5JZY85+OJn2eE7aPph7QVwrSn RF1L490iqHl8/zyq/hYD4FStcSEgzk+T4Zd/vvqjDs8S2rFUcx5hKQvy5mRYgYu8Pc+f tnpNQGo3MWgl5u4Y2Xeb6LOFdZjSdPREng2ANjnb0WBgSkx2V+Or5OUxjpy1mWdAZc/W EMfpsNCbbx4dNtBNggfp5jy4rYI/Uw4XBOclHsh3hVvAAJTtlnB3FkB7CzstCzvbkpPe ZWI7Ab+P+lCkmlplljgKSrGzs1vX3oc7L7qyOaqxIstsVMGg14PR3jBsvHebuF4Qam95 JBkQ== 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=R3KnRES3utzutIHR+CadpCOx6SRhAR/8b5+CyRdke3s=; b=LpjptkU4K5f0wxRSvoNtTfyGGE8Z0Jg88MthTbSUS4q5+CqDnnz7GuTSe2sAw3x56J wdJk/s1FD8+L6y1CrI8S8odRPbaR03YJu+9zu4j7cXc7UCPhxCVEVC9UHKM5RPgW6GT5 EtK+fSddkw+ETphtQmd++LZSIYinbf1KkU6A3z/32b2BWObhoGhOUfXTjSwC8wOQabbx T8XipdDn6eY0iSqip0OTE8EocbcgaDII1W0rGpVraGi4XegWZsJrdPiuOC5C2ZMB7kUp EcQfB6DzKAVXs2tqAswSPeYSBtQQPow4DNysv9w3ErMP+/q2c+YLR9bAx/0SCrVwIL60 9cRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OsX3IYiV; 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 33si38164745plg.62.2019.01.11.11.14.38; Fri, 11 Jan 2019 11:14:54 -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=OsX3IYiV; 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 S1732719AbfAKO1A (ORCPT + 99 others); Fri, 11 Jan 2019 09:27:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:33934 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387861AbfAKORb (ORCPT ); Fri, 11 Jan 2019 09:17:31 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 BC5D72177B; Fri, 11 Jan 2019 14:17:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547216251; bh=xaMGKVsLRsPj3RTnr+lHbGGaokaXLEBxh07LtxnQ3G8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OsX3IYiVZzmGhl+rUp1n1PjsBZ701DbvXLlFsIa0XKx/PuGd8+pcsOPur1ZFjbJDL +zJF+v4aoKFwyrpStkSKpcxElfBL3gdWKqKLdJd4y4Mxbs7BY/Ww7pVum3Lz3mT0Zc /qo5BdaxbOVwfqwHpQlzYC4rP+/97ynubVyLmfH8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Gustavo A. R. Silva" , Takashi Iwai Subject: [PATCH 4.4 30/88] ALSA: rme9652: Fix potential Spectre v1 vulnerability Date: Fri, 11 Jan 2019 15:07:59 +0100 Message-Id: <20190111131050.532349010@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190111131045.137499039@linuxfoundation.org> References: <20190111131045.137499039@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Gustavo A. R. Silva commit 0b84304ef5da92add8dc75a1b07879c5374cdb05 upstream. info->channel is indirectly controlled by user-space, hence leading to a potential exploitation of the Spectre variant 1 vulnerability. This issue was detected with the help of Smatch: sound/pci/rme9652/hdsp.c:4100 snd_hdsp_channel_info() warn: potential spectre issue 'hdsp->channel_map' [r] (local cap) Fix this by sanitizing info->channel before using it to index hdsp->channel_map Notice that given that speculation windows are large, the policy is to kill the speculation on the first load and not worry if it can be completed with a dependent load/store [1]. Also, notice that I refactored the code a bit in order to get rid of the following checkpatch warning: ERROR: do not use assignment in if condition FILE: sound/pci/rme9652/hdsp.c:4103: if ((mapped_channel = hdsp->channel_map[info->channel]) < 0) [1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2 Cc: stable@vger.kernel.org Signed-off-by: Gustavo A. R. Silva Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/pci/rme9652/hdsp.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/sound/pci/rme9652/hdsp.c +++ b/sound/pci/rme9652/hdsp.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -4065,15 +4066,16 @@ static int snd_hdsp_channel_info(struct struct snd_pcm_channel_info *info) { struct hdsp *hdsp = snd_pcm_substream_chip(substream); - int mapped_channel; + unsigned int channel = info->channel; - if (snd_BUG_ON(info->channel >= hdsp->max_channels)) + if (snd_BUG_ON(channel >= hdsp->max_channels)) return -EINVAL; + channel = array_index_nospec(channel, hdsp->max_channels); - if ((mapped_channel = hdsp->channel_map[info->channel]) < 0) + if (hdsp->channel_map[channel] < 0) return -EINVAL; - info->offset = mapped_channel * HDSP_CHANNEL_BUFFER_BYTES; + info->offset = hdsp->channel_map[channel] * HDSP_CHANNEL_BUFFER_BYTES; info->first = 0; info->step = 32; return 0;