summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>2021-09-24 14:24:14 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-11-26 10:47:23 +0100
commit46a8e16fcf2c026837ee602a5e5602fa93f81b5f (patch)
tree22cee5feb5b75043eeac5734617ce32a37d1a2be
parent293385739d687be1b6f791bef03956a14214656d (diff)
downloadlinux-stable-46a8e16fcf2c026837ee602a5e5602fa93f81b5f.tar.gz
linux-stable-46a8e16fcf2c026837ee602a5e5602fa93f81b5f.tar.bz2
linux-stable-46a8e16fcf2c026837ee602a5e5602fa93f81b5f.zip
ALSA: hda: hdac_stream: fix potential locking issue in snd_hdac_stream_assign()
commit 1465d06a6d8580e73ae65f8590392df58c5ed2fd upstream. The fields 'opened', 'running', 'assigned_key' are all protected by a spinlock, but the spinlock is not taken when looking for a stream. This can result in a possible race between assign() and release(). Fix by taking the spinlock before walking through the bus stream list. Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Link: https://lore.kernel.org/r/20210924192417.169243-2-pierre-louis.bossart@linux.intel.com Signed-off-by: Takashi Iwai <tiwai@suse.de> Cc: Scott Bruce <smbruce@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--sound/hda/hdac_stream.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/sound/hda/hdac_stream.c b/sound/hda/hdac_stream.c
index 682ed39f79b0..b299b8b7f871 100644
--- a/sound/hda/hdac_stream.c
+++ b/sound/hda/hdac_stream.c
@@ -289,6 +289,7 @@ struct hdac_stream *snd_hdac_stream_assign(struct hdac_bus *bus,
int key = (substream->pcm->device << 16) | (substream->number << 2) |
(substream->stream + 1);
+ spin_lock_irq(&bus->reg_lock);
list_for_each_entry(azx_dev, &bus->stream_list, list) {
if (azx_dev->direction != substream->stream)
continue;
@@ -302,13 +303,12 @@ struct hdac_stream *snd_hdac_stream_assign(struct hdac_bus *bus,
res = azx_dev;
}
if (res) {
- spin_lock_irq(&bus->reg_lock);
res->opened = 1;
res->running = 0;
res->assigned_key = key;
res->substream = substream;
- spin_unlock_irq(&bus->reg_lock);
}
+ spin_unlock_irq(&bus->reg_lock);
return res;
}
EXPORT_SYMBOL_GPL(snd_hdac_stream_assign);