Skip to content

Commit

Permalink
ALSA: opl3: Hardening for potential Spectre v1
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
tiwai committed Apr 25, 2018
1 parent 69fa6f1 commit 7f054a5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions sound/drivers/opl3/opl3_synth.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <linux/slab.h>
#include <linux/export.h>
#include <linux/nospec.h>
#include <sound/opl3.h>
#include <sound/asound_fm.h>

Expand Down Expand Up @@ -448,7 +449,7 @@ static int snd_opl3_set_voice(struct snd_opl3 * opl3, struct snd_dm_fm_voice * v
{
unsigned short reg_side;
unsigned char op_offset;
unsigned char voice_offset;
unsigned char voice_offset, voice_op;

unsigned short opl3_reg;
unsigned char reg_val;
Expand All @@ -473,7 +474,9 @@ static int snd_opl3_set_voice(struct snd_opl3 * opl3, struct snd_dm_fm_voice * v
voice_offset = voice->voice - MAX_OPL2_VOICES;
}
/* Get register offset of operator */
op_offset = snd_opl3_regmap[voice_offset][voice->op];
voice_offset = array_index_nospec(voice_offset, MAX_OPL2_VOICES);
voice_op = array_index_nospec(voice->op, 4);
op_offset = snd_opl3_regmap[voice_offset][voice_op];

reg_val = 0x00;
/* Set amplitude modulation (tremolo) effect */
Expand Down

0 comments on commit 7f054a5

Please sign in to comment.