Revert "ALSA: pcm: Fix races among concurrent prepare and hw_params/hw_free calls"

This reverts commit cb6a39c5eb.

It will come back after the next ABI break as it is needed to resolve
CVE-2022-1048.  But for now, while testing, it can be reverted in order
to preserve the ABI.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I52c67352b87bc95efab566d76f95d5466a61da64
This commit is contained in:
Greg Kroah-Hartman
2022-03-29 12:55:10 +02:00
parent 07566786dc
commit f9e40dc812

View File

@@ -1177,17 +1177,15 @@ struct action_ops {
static int snd_pcm_action_group(const struct action_ops *ops, static int snd_pcm_action_group(const struct action_ops *ops,
struct snd_pcm_substream *substream, struct snd_pcm_substream *substream,
snd_pcm_state_t state, snd_pcm_state_t state,
bool stream_lock) bool do_lock)
{ {
struct snd_pcm_substream *s = NULL; struct snd_pcm_substream *s = NULL;
struct snd_pcm_substream *s1; struct snd_pcm_substream *s1;
int res = 0, depth = 1; int res = 0, depth = 1;
snd_pcm_group_for_each_entry(s, substream) { snd_pcm_group_for_each_entry(s, substream) {
if (s != substream) { if (do_lock && s != substream) {
if (!stream_lock) if (s->pcm->nonatomic)
mutex_lock_nested(&s->runtime->buffer_mutex, depth);
else if (s->pcm->nonatomic)
mutex_lock_nested(&s->self_group.mutex, depth); mutex_lock_nested(&s->self_group.mutex, depth);
else else
spin_lock_nested(&s->self_group.lock, depth); spin_lock_nested(&s->self_group.lock, depth);
@@ -1215,12 +1213,11 @@ static int snd_pcm_action_group(const struct action_ops *ops,
ops->post_action(s, state); ops->post_action(s, state);
} }
_unlock: _unlock:
if (do_lock) {
/* unlock streams */ /* unlock streams */
snd_pcm_group_for_each_entry(s1, substream) { snd_pcm_group_for_each_entry(s1, substream) {
if (s1 != substream) { if (s1 != substream) {
if (!stream_lock) if (s1->pcm->nonatomic)
mutex_unlock(&s1->runtime->buffer_mutex);
else if (s1->pcm->nonatomic)
mutex_unlock(&s1->self_group.mutex); mutex_unlock(&s1->self_group.mutex);
else else
spin_unlock(&s1->self_group.lock); spin_unlock(&s1->self_group.lock);
@@ -1228,6 +1225,7 @@ static int snd_pcm_action_group(const struct action_ops *ops,
if (s1 == s) /* end */ if (s1 == s) /* end */
break; break;
} }
}
return res; return res;
} }
@@ -1356,12 +1354,10 @@ static int snd_pcm_action_nonatomic(const struct action_ops *ops,
/* Guarantee the group members won't change during non-atomic action */ /* Guarantee the group members won't change during non-atomic action */
down_read(&snd_pcm_link_rwsem); down_read(&snd_pcm_link_rwsem);
mutex_lock(&substream->runtime->buffer_mutex);
if (snd_pcm_stream_linked(substream)) if (snd_pcm_stream_linked(substream))
res = snd_pcm_action_group(ops, substream, state, false); res = snd_pcm_action_group(ops, substream, state, false);
else else
res = snd_pcm_action_single(ops, substream, state); res = snd_pcm_action_single(ops, substream, state);
mutex_unlock(&substream->runtime->buffer_mutex);
up_read(&snd_pcm_link_rwsem); up_read(&snd_pcm_link_rwsem);
return res; return res;
} }