aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2018-04-24 01:56:07 -0400
committerTakashi Iwai <tiwai@suse.de>2018-04-25 04:37:47 -0400
commit7f054a5bee0987f1e2d4e59daea462421c76f2cb (patch)
tree31ef4ea6ea8237bba834fcbedac06c8463318338
parent69fa6f19b95597618ab30438a27b67ad93daa7c7 (diff)
ALSA: opl3: Hardening for potential Spectre v1
As recently Smatch suggested, one place in OPL3 driver may expand the array directly from the user-space value with speculation: sound/drivers/opl3/opl3_synth.c:476 snd_opl3_set_voice() warn: potential spectre issue 'snd_opl3_regmap' 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/drivers/opl3/opl3_synth.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/sound/drivers/opl3/opl3_synth.c b/sound/drivers/opl3/opl3_synth.c
index ddcc1a325a61..42920a243328 100644
--- a/sound/drivers/opl3/opl3_synth.c
+++ b/sound/drivers/opl3/opl3_synth.c
@@ -21,6 +21,7 @@
21 21
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/export.h> 23#include <linux/export.h>
24#include <linux/nospec.h>
24#include <sound/opl3.h> 25#include <sound/opl3.h>
25#include <sound/asound_fm.h> 26#include <sound/asound_fm.h>
26 27
@@ -448,7 +449,7 @@ static int snd_opl3_set_voice(struct snd_opl3 * opl3, struct snd_dm_fm_voice * v
448{ 449{
449 unsigned short reg_side; 450 unsigned short reg_side;
450 unsigned char op_offset; 451 unsigned char op_offset;
451 unsigned char voice_offset; 452 unsigned char voice_offset, voice_op;
452 453
453 unsigned short opl3_reg; 454 unsigned short opl3_reg;
454 unsigned char reg_val; 455 unsigned char reg_val;
@@ -473,7 +474,9 @@ static int snd_opl3_set_voice(struct snd_opl3 * opl3, struct snd_dm_fm_voice * v
473 voice_offset = voice->voice - MAX_OPL2_VOICES; 474 voice_offset = voice->voice - MAX_OPL2_VOICES;
474 } 475 }
475 /* Get register offset of operator */ 476 /* Get register offset of operator */
476 op_offset = snd_opl3_regmap[voice_offset][voice->op]; 477 voice_offset = array_index_nospec(voice_offset, MAX_OPL2_VOICES);
478 voice_op = array_index_nospec(voice->op, 4);
479 op_offset = snd_opl3_regmap[voice_offset][voice_op];
477 480
478 reg_val = 0x00; 481 reg_val = 0x00;
479 /* Set amplitude modulation (tremolo) effect */ 482 /* Set amplitude modulation (tremolo) effect */