Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3528989imu; Mon, 7 Jan 2019 05:08:55 -0800 (PST) X-Google-Smtp-Source: ALg8bN7COogjruX+9UZeVpNNBbEXg/kcoqyk3mLR4QaeGX7/5f8UfH/zzW/0/nNJqf0AmNkzhjfP X-Received: by 2002:a65:590b:: with SMTP id f11mr10927375pgu.60.1546866535063; Mon, 07 Jan 2019 05:08:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546866535; cv=none; d=google.com; s=arc-20160816; b=P2YdXPdh8FTH9xVfjBGGkHUmQV70j5N0062s/3XXTZ4aWyZ0ObcChUYEoFSWvfBF+U HH8aY6rQ0s6fhWJBmlAbhO5ln/DLmk555/OzRgwxFgsO80LMCzvLvrOcaDtARKCj8nvj Lors+w+WQu5EGG8lYeMBGs4uFqM+P5zKXcA41tlUONJ8KiXYhPpv9pU2SMePw70PhU4O YW250mqUFAN+j7ushcBLwK/A6Aod2BVToGUM8BkTgFX/dBEfUFCoHQOWdlK9LE80gZA5 rm2KHr6BcFcpkypBiIlf75fjI7XFdYwtilbVypuHFQITP6+2Vy3c9Ot5Uunbdb0Y9mKJ j8GA== 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=4aJB9AbHml33BEwbjdHhV+0gRtT+ufKomISD/Eq9Ucg=; b=QylzUO5RsKPPOElyRL/HUP94d8WK/Vch6KtJmKgUehbtdRa1my7JgLBgnWvI4vsV2d qsovKI9Dj4aAEWlaY6At7xv7HdNEA958VXiuCiNtDGo+J1hdvl2NfCNxJ3v6HxD6BBou kuHq91T+F1FH/I6uJfdjqUb/wmJHzvPFrrQwAMSZTmFZ4Ht3OxvlULC+WO4WuQ2QxdHl /Dd/zdn97QIefuVh26Ib+jYX3z2ChPurs48IdmuMK0/zSP8DANyyZcqWM10Fz6Z642Gg 47DrAzJI/q5igAX2uGoKQgEuy5ICWdXKZSsFgy+O4jaNvQAw+9w1cQsG9LtggPrmcPy5 qqqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="d/cIq3q5"; 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 w31si10595245pla.308.2019.01.07.05.08.39; Mon, 07 Jan 2019 05:08:55 -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="d/cIq3q5"; 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 S1730973AbfAGNGo (ORCPT + 99 others); Mon, 7 Jan 2019 08:06:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:54022 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727362AbfAGNGm (ORCPT ); Mon, 7 Jan 2019 08:06:42 -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 3B4422089F; Mon, 7 Jan 2019 13:06:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546866401; bh=pMpeoezp/GEILklmnZWSnU2Vg/WC3omOpGwKR7jb2vc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d/cIq3q5qA4AZEVyqpRwCsSlDHSiqWRUqSRJom79RK2zaWUWdu+kSk2SXXNUXYBSb amrpN35OTRN7FE1jp8HLpGHT6Qj/renv0WN0s7SyUujRUbVVHewuE2W7zA3NNR/Jv7 ZQYGkVAgKi2rmRTy1l8PU8qnQvDplfsflMKJppDI= 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.9 30/71] ALSA: rme9652: Fix potential Spectre v1 vulnerability Date: Mon, 7 Jan 2019 13:32:59 +0100 Message-Id: <20190107105334.474006236@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190107105330.280153213@linuxfoundation.org> References: <20190107105330.280153213@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.9-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;