Commit f526afcd authored by Takashi Iwai's avatar Takashi Iwai

ALSA: rme9652: Hardening for potential Spectre v1

As recently Smatch suggested, one place in RME9652 driver may expand
the array directly from the user-space value with speculation:
  sound/pci/rme9652/rme9652.c:2074 snd_rme9652_channel_info() warn: potential spectre issue 'rme9652->channel_map' (local cap)

This patch puts array_index_nospec() for hardening against it.

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 10513142
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/module.h> #include <linux/module.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>
...@@ -2071,9 +2072,10 @@ static int snd_rme9652_channel_info(struct snd_pcm_substream *substream, ...@@ -2071,9 +2072,10 @@ static int snd_rme9652_channel_info(struct snd_pcm_substream *substream,
if (snd_BUG_ON(info->channel >= RME9652_NCHANNELS)) if (snd_BUG_ON(info->channel >= RME9652_NCHANNELS))
return -EINVAL; return -EINVAL;
if ((chn = rme9652->channel_map[info->channel]) < 0) { chn = rme9652->channel_map[array_index_nospec(info->channel,
RME9652_NCHANNELS)];
if (chn < 0)
return -EINVAL; return -EINVAL;
}
info->offset = chn * RME9652_CHANNEL_BUFFER_BYTES; info->offset = chn * RME9652_CHANNEL_BUFFER_BYTES;
info->first = 0; info->first = 0;
......
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