Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3775886imu; Mon, 7 Jan 2019 09:13:01 -0800 (PST) X-Google-Smtp-Source: ALg8bN4SXrGK8g3hDb/3FjApOCfIrVu6PFxhD5A5vmiIX/UfRghDoU+BMnrUDHbWq97TwJFhpIE2 X-Received: by 2002:a17:902:4a0c:: with SMTP id w12mr62511083pld.8.1546881181635; Mon, 07 Jan 2019 09:13:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546881181; cv=none; d=google.com; s=arc-20160816; b=i/2gTzFNKIJIHbgId4oQEdES5heiL47NfBYZMfMrPBea12qbpi+RH8kw5DsSrImLRE tsHn2Z+Bm3NbadkBz/UfKnCZVA2+E8Yz75JMHvYdQ99NRn7wQX4zxf7h699IWrKpEkQ/ CDEFoFrY8r6bqCFoY/GplDYehtv4lvv5mFo9gNnLwoakiGvkJy6jkeBucAxmnD4qxphP J/VymlLW+dk50P3cXUOl5e65fqEa/KzdbOcnEX8dW/wCuY7RTieNZa4BW26BQxEX389z k4eRzKYMzIa8wdu4Ebm4YVYhXe4HzyFsDsE2HxLOXa1uq7Mtkm69hl5e07LNXwR0LAmw M3tQ== 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=ejxfqyYbLmLdHu7bvXQ99NkMBMbi0ya/oG9hi9cNVcs=; b=i3khDwn7T07aSDlPCjZi6qGeK3U4eYLvSS2cBFM0S6mXyyaAX9wQQYSP+kYpoTG3Zm 8BTrNbv4soVfZVcvEMuatKhOKOuvMYlw8YH7FiG6FlVv39wRgxkn/jVFiOzc4/K0wM2C IGjZMOEEVjSdV4XYZWucjeNw1NWD1XRglbCPcRMZvX08olXuMbVf38ovAFZuexel0jCQ uVcnxPggGZITG1cj6MVgWp0GX5Xv937Rdpxm9KXH0lCa+rykWf/MF53nb1oejUYWcbhn 7knpjbVRQv8Fo00YRmJYud/RVlUnrVDZGKXDykDw78TM32S/82uEz1te78lhgQ1ozNKU RoPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EHHvRWzW; 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 f17si10080982pgj.208.2019.01.07.09.12.46; Mon, 07 Jan 2019 09:13:01 -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=EHHvRWzW; 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 S1730605AbfAGNBY (ORCPT + 99 others); Mon, 7 Jan 2019 08:01:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:48826 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730577AbfAGNBV (ORCPT ); Mon, 7 Jan 2019 08:01:21 -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 BD3D021736; Mon, 7 Jan 2019 13:01:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546866080; bh=6Ae/7jO+QHtcjTwwTb99mBZ/QN/wMf8NeU9mxsTyLIs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EHHvRWzWcj1W282nu9Ua8jw6CkZGBToN+LUdeaWwIze4jHmxnyq3xiHcOrSWQM5W7 OECP4sryt6AsHev36lkrjj1Dr6TcaJblEZ+dO3fEO3Xcm8SvijXmG4DtAh+KhzIhH4 8YMSCIWWSSGBEcGI+AB37QPvWMdIaGt7ildo8kx4= 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.14 038/101] ALSA: rme9652: Fix potential Spectre v1 vulnerability Date: Mon, 7 Jan 2019 13:32:26 +0100 Message-Id: <20190107105334.991118836@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190107105330.372621917@linuxfoundation.org> References: <20190107105330.372621917@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.14-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;