Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3766722imu; Mon, 7 Jan 2019 09:04:45 -0800 (PST) X-Google-Smtp-Source: AFSGD/XucBy4LtEQ6ff3TKjPXwn9NiUEXCHlV96uZ6E3pZtsgGoOr+st/SMeHq93yo7v065OkKRw X-Received: by 2002:a62:5182:: with SMTP id f124mr64151617pfb.238.1546880685206; Mon, 07 Jan 2019 09:04:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546880685; cv=none; d=google.com; s=arc-20160816; b=eDXLq8NJpHLkvhdCh6OAM1n2TtTQo13D3DC5Fa7QT2f9EH8Wp1/hlDJ2dSFOfceO/E R6UD73j/FhdWgTqOs7bmBsEOIzogM663dLYU8Mz1Q07kX6eQcwCRdgg2wTRSWaMMotRU 9EdK9FvEZDPkD7jnQaA06NXEH/uIfOfqb9jspR6ZbQeivRlGd5r4/Zr+pAjTUlv3Kyfr plIz+aMklNheCCNipZex7Foa4rI+FbBO3rUuRmqxmqUqst5WqEN7YeEiAV2L/838foR3 tCML9ki3Jz96llimAt23Q4E0ISHH0OxXfvqPZUS7W8lIFtDuHkKx14gwAmaMGSwoTbhf QU2w== 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=mp2bZ0sDTwtFrg3PUQaRLDVyyLfOIvNxgoIkSWaeHAU=; b=tdQRakZDN4nqOc+V4rkUT6tZ30Zvc0XCbQEUMyQgoba5xSuqURG27C549/fYNLBp4F daW5tAMT+lay/Zq53AZV23Ip8dg2BHXlFelm80l1dkJmJhWRCQkHdE8gyQLga2cXFm7s 7LbwzKiJ0u/QQHDeHUVsqtxgD7qbGCSalArGb3M65VtZQeriCbuQ0BCqz+owOf1MEhJ6 r6se/uoibolA4WGe7MdlFyN8dXik7MR2RI9uHV7IZ2YSHVKxzOF1GyMv3T2teHs4XXb7 jzxFuDU4NPKaaAKBv97PUA71MyMWGzbl2MWlvhH/r+Xjoimc00s/lSSMG9eq0CQ63Qt6 08Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=w6gmEUeP; 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 x23si24205606pgj.247.2019.01.07.09.04.29; Mon, 07 Jan 2019 09:04:45 -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=w6gmEUeP; 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 S1727244AbfAGMea (ORCPT + 99 others); Mon, 7 Jan 2019 07:34:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:46786 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726963AbfAGMe2 (ORCPT ); Mon, 7 Jan 2019 07:34:28 -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 E7B5E2183F; Mon, 7 Jan 2019 12:34:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546864467; bh=5Tp1Kv1q+hw5D0VosRq/pgDJccykAFJDZ6uU14VpnCw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w6gmEUePS39DZFFfPpLOfKcN0xLLpKRx6IsDceTUTa7ODUfxm/g7g608WcnC7eC3l tpqqzcZBVmIIi4oXyYUr84ygfEivob0AOdLHv+dAJx9OAqkP/uhtTya4y5U0vHqiHi peKK+A9apoQozEyAR7wOmv6U4HywTNnJgK8NZ80A= 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.20 021/145] ALSA: rme9652: Fix potential Spectre v1 vulnerability Date: Mon, 7 Jan 2019 13:30:58 +0100 Message-Id: <20190107104440.082737456@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190107104437.308206189@linuxfoundation.org> References: <20190107104437.308206189@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.20-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 @@ -4092,15 +4093,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;