Received: by 10.192.165.148 with SMTP id m20csp4189898imm; Mon, 30 Apr 2018 13:30:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp3gxjVzRyprtN9vXTqnsbJ0W7W5AKzsSsPFhFUYU3i7futa+liDo/x4xI5rAEkbi/n+L+W X-Received: by 2002:a17:902:2924:: with SMTP id g33-v6mr13865993plb.26.1525120258433; Mon, 30 Apr 2018 13:30:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525120258; cv=none; d=google.com; s=arc-20160816; b=uTiorc9rx6Z18L29khMv3w0AJCIsPErA8owbf+nLe6j3yG86WuajkuRDj7UNJswRhp O7tl7C10noKt6vaPUW07sQVsXma3ehne9cjhUpQxkIPfvbY12PgTbAKqlS6l73A87vL6 yoLrEwQhoJeAr5eiOlqU8fi1dDUm7PRRw8ZW9qIM8/C4bsnbhLPCjKTn5JBpWPzwbnvW UIVTklDTxmnSh5RxBm0anrH+QTnVVgjfIivUJUQgwQrEWnEsZ8BSao/I+/V95UupI9IW TDfqsD5nsv43RR6leLhGM+XMKKT7BRVffRBLyZjri0hj2D7s8MvcW8519QF9OGtPuJm3 vfPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=JhQkm/ZuSSXgHWGxvOFcmdrjW0kfS0EKQVb7mDDjwDE=; b=g0h0uF5COdwEPik0WIkxABVJma0Q4mD3jB+e+1j6R63mn0//4vPw+6YM6XEGHhdEhN 2waT83AKODbXKD7EvjA9ThunkgGE+AYCRyaUqFg6gsr6mGYRpz2i7us+hCg5zfaIbR95 FNw7eg95XVlA9qI6r+qQUYQ/iTqX3+y0X/z0yhEdoaL1/hTfbzUpyvuhs00X1GMw4+EY 63anb5gYx+ktQrSWqsPGoO3dbIP7ZB6iW8q66supn3jHpxRh1+XxF04j4j4Mf33vuPid YtfWLClP0LRZ5z/Bso63Ipw4JXKyCxxm0SPCQo/jpm0MOSg3hUo9k3QFpEgmaNxCFGJ9 wEqw== ARC-Authentication-Results: i=1; mx.google.com; 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 q14-v6si7705778pls.286.2018.04.30.13.30.44; Mon, 30 Apr 2018 13:30:58 -0700 (PDT) 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; 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 S1755557AbeD3T0O (ORCPT + 99 others); Mon, 30 Apr 2018 15:26:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:59548 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755528AbeD3T0M (ORCPT ); Mon, 30 Apr 2018 15:26:12 -0400 Received: from localhost (unknown [104.132.1.102]) (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 0EF1322DC0; Mon, 30 Apr 2018 19:26:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0EF1322DC0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Takashi Iwai Subject: [PATCH 4.4 22/44] ALSA: hdspm: Hardening for potential Spectre v1 Date: Mon, 30 Apr 2018 12:24:33 -0700 Message-Id: <20180430190947.226606164@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430190946.093694747@linuxfoundation.org> References: <20180430190946.093694747@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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: Takashi Iwai commit 10513142a7114d251670361ad40cba2c61403406 upstream. As recently Smatch suggested, a couple of places in HDSP MADI driver may expand the array directly from the user-space value with speculation: sound/pci/rme9652/hdspm.c:5717 snd_hdspm_channel_info() warn: potential spectre issue 'hdspm->channel_map_out' (local cap) sound/pci/rme9652/hdspm.c:5734 snd_hdspm_channel_info() warn: potential spectre issue 'hdspm->channel_map_in' (local cap) This patch puts array_index_nospec() for hardening against them. BugLink: https://marc.info/?l=linux-kernel&m=152411496503418&w=2 Reported-by: Dan Carpenter Cc: Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/pci/rme9652/hdspm.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) --- a/sound/pci/rme9652/hdspm.c +++ b/sound/pci/rme9652/hdspm.c @@ -137,6 +137,7 @@ #include #include #include +#include #include #include @@ -5692,40 +5693,43 @@ static int snd_hdspm_channel_info(struct struct snd_pcm_channel_info *info) { struct hdspm *hdspm = snd_pcm_substream_chip(substream); + unsigned int channel = info->channel; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { - if (snd_BUG_ON(info->channel >= hdspm->max_channels_out)) { + if (snd_BUG_ON(channel >= hdspm->max_channels_out)) { dev_info(hdspm->card->dev, "snd_hdspm_channel_info: output channel out of range (%d)\n", - info->channel); + channel); return -EINVAL; } - if (hdspm->channel_map_out[info->channel] < 0) { + channel = array_index_nospec(channel, hdspm->max_channels_out); + if (hdspm->channel_map_out[channel] < 0) { dev_info(hdspm->card->dev, "snd_hdspm_channel_info: output channel %d mapped out\n", - info->channel); + channel); return -EINVAL; } - info->offset = hdspm->channel_map_out[info->channel] * + info->offset = hdspm->channel_map_out[channel] * HDSPM_CHANNEL_BUFFER_BYTES; } else { - if (snd_BUG_ON(info->channel >= hdspm->max_channels_in)) { + if (snd_BUG_ON(channel >= hdspm->max_channels_in)) { dev_info(hdspm->card->dev, "snd_hdspm_channel_info: input channel out of range (%d)\n", - info->channel); + channel); return -EINVAL; } - if (hdspm->channel_map_in[info->channel] < 0) { + channel = array_index_nospec(channel, hdspm->max_channels_in); + if (hdspm->channel_map_in[channel] < 0) { dev_info(hdspm->card->dev, "snd_hdspm_channel_info: input channel %d mapped out\n", - info->channel); + channel); return -EINVAL; } - info->offset = hdspm->channel_map_in[info->channel] * + info->offset = hdspm->channel_map_in[channel] * HDSPM_CHANNEL_BUFFER_BYTES; }