Commit 10513142 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: hdspm: Hardening for potential Spectre v1

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=2Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent f9d94b57
...@@ -137,6 +137,7 @@ ...@@ -137,6 +137,7 @@
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/math64.h> #include <linux/math64.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/nospec.h>
#include <sound/core.h> #include <sound/core.h>
#include <sound/control.h> #include <sound/control.h>
...@@ -5698,40 +5699,43 @@ static int snd_hdspm_channel_info(struct snd_pcm_substream *substream, ...@@ -5698,40 +5699,43 @@ static int snd_hdspm_channel_info(struct snd_pcm_substream *substream,
struct snd_pcm_channel_info *info) struct snd_pcm_channel_info *info)
{ {
struct hdspm *hdspm = snd_pcm_substream_chip(substream); struct hdspm *hdspm = snd_pcm_substream_chip(substream);
unsigned int channel = info->channel;
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 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, dev_info(hdspm->card->dev,
"snd_hdspm_channel_info: output channel out of range (%d)\n", "snd_hdspm_channel_info: output channel out of range (%d)\n",
info->channel); channel);
return -EINVAL; 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, dev_info(hdspm->card->dev,
"snd_hdspm_channel_info: output channel %d mapped out\n", "snd_hdspm_channel_info: output channel %d mapped out\n",
info->channel); channel);
return -EINVAL; return -EINVAL;
} }
info->offset = hdspm->channel_map_out[info->channel] * info->offset = hdspm->channel_map_out[channel] *
HDSPM_CHANNEL_BUFFER_BYTES; HDSPM_CHANNEL_BUFFER_BYTES;
} else { } 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, dev_info(hdspm->card->dev,
"snd_hdspm_channel_info: input channel out of range (%d)\n", "snd_hdspm_channel_info: input channel out of range (%d)\n",
info->channel); channel);
return -EINVAL; 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, dev_info(hdspm->card->dev,
"snd_hdspm_channel_info: input channel %d mapped out\n", "snd_hdspm_channel_info: input channel %d mapped out\n",
info->channel); channel);
return -EINVAL; return -EINVAL;
} }
info->offset = hdspm->channel_map_in[info->channel] * info->offset = hdspm->channel_map_in[channel] *
HDSPM_CHANNEL_BUFFER_BYTES; HDSPM_CHANNEL_BUFFER_BYTES;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment