aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2018-04-24 02:04:41 -0400
committerTakashi Iwai <tiwai@suse.de>2018-04-25 04:37:48 -0400
commitf526afcd8f71945c23ce581d7864ace93de8a4f7 (patch)
tree910de0bc4f2596055400f6c7e501ad28b3dd664f
parent10513142a7114d251670361ad40cba2c61403406 (diff)
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=2 Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--sound/pci/rme9652/rme9652.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/sound/pci/rme9652/rme9652.c b/sound/pci/rme9652/rme9652.c
index df648b1d9217..edd765e22377 100644
--- a/sound/pci/rme9652/rme9652.c
+++ b/sound/pci/rme9652/rme9652.c
@@ -26,6 +26,7 @@
26#include <linux/pci.h> 26#include <linux/pci.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/io.h> 28#include <linux/io.h>
29#include <linux/nospec.h>
29 30
30#include <sound/core.h> 31#include <sound/core.h>
31#include <sound/control.h> 32#include <sound/control.h>
@@ -2071,9 +2072,10 @@ static int snd_rme9652_channel_info(struct snd_pcm_substream *substream,
2071 if (snd_BUG_ON(info->channel >= RME9652_NCHANNELS)) 2072 if (snd_BUG_ON(info->channel >= RME9652_NCHANNELS))
2072 return -EINVAL; 2073 return -EINVAL;
2073 2074
2074 if ((chn = rme9652->channel_map[info->channel]) < 0) { 2075 chn = rme9652->channel_map[array_index_nospec(info->channel,
2076 RME9652_NCHANNELS)];
2077 if (chn < 0)
2075 return -EINVAL; 2078 return -EINVAL;
2076 }
2077 2079
2078 info->offset = chn * RME9652_CHANNEL_BUFFER_BYTES; 2080 info->offset = chn * RME9652_CHANNEL_BUFFER_BYTES;
2079 info->first = 0; 2081 info->first = 0;