From: Takashi Iwai <tiwai@suse.de>
To: alsa-devel@alsa-project.org
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Subject: [PATCH 3/8] ALSA: control: Hardening for potential Spectre v1
Date: Tue, 24 Apr 2018 09:56:14 +0200 [thread overview]
Message-ID: <20180424075619.29602-4-tiwai@suse.de> (raw)
In-Reply-To: <20180424075619.29602-1-tiwai@suse.de>
As the recent Smatch warned, a few places in ALSA control core codes
may expand the array directly from the user-space value with
speculation:
sound/core/control.c:1003 snd_ctl_elem_lock() warn: potential spectre issue 'kctl->vd'
sound/core/control.c:1031 snd_ctl_elem_unlock() warn: potential spectre issue 'kctl->vd'
sound/core/control.c:844 snd_ctl_elem_info() warn: potential spectre issue 'kctl->vd'
sound/core/control.c:891 snd_ctl_elem_read() warn: potential spectre issue 'kctl->vd'
sound/core/control.c:939 snd_ctl_elem_write() warn: potential spectre issue 'kctl->vd'
Although all these seem doing only the first load without further
reference, we may want to stay in a safer side, so hardening with
array_index_nospec() would still make sense.
In this patch, we put array_index_nospec() to the common
snd_ctl_get_ioff*() helpers instead of each caller. They are also
referred from some drivers, too, and basically all usages are to
calculate the array index from the user-space value.
BugLink: https://marc.info/?l=linux-kernel&m=152411496503418&w=2
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
include/sound/control.h | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/include/sound/control.h b/include/sound/control.h
index ca13a44ae9d4..6011a58d3e20 100644
--- a/include/sound/control.h
+++ b/include/sound/control.h
@@ -23,6 +23,7 @@
*/
#include <linux/wait.h>
+#include <linux/nospec.h>
#include <sound/asound.h>
#define snd_kcontrol_chip(kcontrol) ((kcontrol)->private_data)
@@ -148,12 +149,14 @@ int snd_ctl_get_preferred_subdevice(struct snd_card *card, int type);
static inline unsigned int snd_ctl_get_ioffnum(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id)
{
- return id->numid - kctl->id.numid;
+ unsigned int ioff = id->numid - kctl->id.numid;
+ return array_index_nospec(ioff, kctl->count);
}
static inline unsigned int snd_ctl_get_ioffidx(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id)
{
- return id->index - kctl->id.index;
+ unsigned int ioff = id->index - kctl->id.index;
+ return array_index_nospec(ioff, kctl->count);
}
static inline unsigned int snd_ctl_get_ioff(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id)
--
2.16.3
next prev parent reply other threads:[~2018-04-24 7:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-24 7:56 [PATCH 0/8] ALSA: Hardening for potential Spectre v1 Takashi Iwai
2018-04-24 7:56 ` [PATCH 1/8] ALSA: seq: oss: Fix unbalanced use lock for synth MIDI device Takashi Iwai
2018-04-24 7:56 ` [PATCH 2/8] ALSA: seq: oss: Hardening for potential Spectre v1 Takashi Iwai
2018-04-24 7:56 ` Takashi Iwai [this message]
2018-04-24 7:56 ` [PATCH 4/8] ALSA: hda: " Takashi Iwai
2018-04-24 7:56 ` [PATCH 5/8] ALSA: opl3: " Takashi Iwai
2018-04-24 7:56 ` [PATCH 6/8] ALSA: asihpi: " Takashi Iwai
2018-04-24 7:56 ` [PATCH 7/8] ALSA: hdspm: " Takashi Iwai
2018-04-24 7:56 ` [PATCH 8/8] ALSA: rme9652: " Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180424075619.29602-4-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@alsa-project.org \
--cc=dan.carpenter@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox