Commit 88efef63 authored by Takashi Iwai's avatar Takashi Iwai Committed by Stefan Bader

ALSA: aloop: Add missing cable lock to ctl API callbacks

BugLink: http://bugs.launchpad.net/bugs/1774173

commit 76b3421b upstream.

Some control API callbacks in aloop driver are too lazy to take the
loopback->cable_lock and it results in possible races of cable access
while it's being freed.  It eventually lead to a UAF, as reported by
fuzzer recently.

This patch covers such control API callbacks and add the proper mutex
locks.
Reported-by: default avatarDaeRyong Jeong <threeearcat@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
parent ba789e2d
...@@ -832,9 +832,11 @@ static int loopback_rate_shift_get(struct snd_kcontrol *kcontrol, ...@@ -832,9 +832,11 @@ static int loopback_rate_shift_get(struct snd_kcontrol *kcontrol,
{ {
struct loopback *loopback = snd_kcontrol_chip(kcontrol); struct loopback *loopback = snd_kcontrol_chip(kcontrol);
mutex_lock(&loopback->cable_lock);
ucontrol->value.integer.value[0] = ucontrol->value.integer.value[0] =
loopback->setup[kcontrol->id.subdevice] loopback->setup[kcontrol->id.subdevice]
[kcontrol->id.device].rate_shift; [kcontrol->id.device].rate_shift;
mutex_unlock(&loopback->cable_lock);
return 0; return 0;
} }
...@@ -866,9 +868,11 @@ static int loopback_notify_get(struct snd_kcontrol *kcontrol, ...@@ -866,9 +868,11 @@ static int loopback_notify_get(struct snd_kcontrol *kcontrol,
{ {
struct loopback *loopback = snd_kcontrol_chip(kcontrol); struct loopback *loopback = snd_kcontrol_chip(kcontrol);
mutex_lock(&loopback->cable_lock);
ucontrol->value.integer.value[0] = ucontrol->value.integer.value[0] =
loopback->setup[kcontrol->id.subdevice] loopback->setup[kcontrol->id.subdevice]
[kcontrol->id.device].notify; [kcontrol->id.device].notify;
mutex_unlock(&loopback->cable_lock);
return 0; return 0;
} }
...@@ -880,12 +884,14 @@ static int loopback_notify_put(struct snd_kcontrol *kcontrol, ...@@ -880,12 +884,14 @@ static int loopback_notify_put(struct snd_kcontrol *kcontrol,
int change = 0; int change = 0;
val = ucontrol->value.integer.value[0] ? 1 : 0; val = ucontrol->value.integer.value[0] ? 1 : 0;
mutex_lock(&loopback->cable_lock);
if (val != loopback->setup[kcontrol->id.subdevice] if (val != loopback->setup[kcontrol->id.subdevice]
[kcontrol->id.device].notify) { [kcontrol->id.device].notify) {
loopback->setup[kcontrol->id.subdevice] loopback->setup[kcontrol->id.subdevice]
[kcontrol->id.device].notify = val; [kcontrol->id.device].notify = val;
change = 1; change = 1;
} }
mutex_unlock(&loopback->cable_lock);
return change; return change;
} }
...@@ -893,15 +899,18 @@ static int loopback_active_get(struct snd_kcontrol *kcontrol, ...@@ -893,15 +899,18 @@ static int loopback_active_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol) struct snd_ctl_elem_value *ucontrol)
{ {
struct loopback *loopback = snd_kcontrol_chip(kcontrol); struct loopback *loopback = snd_kcontrol_chip(kcontrol);
struct loopback_cable *cable = loopback->cables struct loopback_cable *cable;
[kcontrol->id.subdevice][kcontrol->id.device ^ 1];
unsigned int val = 0; unsigned int val = 0;
mutex_lock(&loopback->cable_lock);
cable = loopback->cables[kcontrol->id.subdevice][kcontrol->id.device ^ 1];
if (cable != NULL) { if (cable != NULL) {
unsigned int running = cable->running ^ cable->pause; unsigned int running = cable->running ^ cable->pause;
val = (running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) ? 1 : 0; val = (running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) ? 1 : 0;
} }
mutex_unlock(&loopback->cable_lock);
ucontrol->value.integer.value[0] = val; ucontrol->value.integer.value[0] = val;
return 0; return 0;
} }
...@@ -944,9 +953,11 @@ static int loopback_rate_get(struct snd_kcontrol *kcontrol, ...@@ -944,9 +953,11 @@ static int loopback_rate_get(struct snd_kcontrol *kcontrol,
{ {
struct loopback *loopback = snd_kcontrol_chip(kcontrol); struct loopback *loopback = snd_kcontrol_chip(kcontrol);
mutex_lock(&loopback->cable_lock);
ucontrol->value.integer.value[0] = ucontrol->value.integer.value[0] =
loopback->setup[kcontrol->id.subdevice] loopback->setup[kcontrol->id.subdevice]
[kcontrol->id.device].rate; [kcontrol->id.device].rate;
mutex_unlock(&loopback->cable_lock);
return 0; return 0;
} }
...@@ -966,9 +977,11 @@ static int loopback_channels_get(struct snd_kcontrol *kcontrol, ...@@ -966,9 +977,11 @@ static int loopback_channels_get(struct snd_kcontrol *kcontrol,
{ {
struct loopback *loopback = snd_kcontrol_chip(kcontrol); struct loopback *loopback = snd_kcontrol_chip(kcontrol);
mutex_lock(&loopback->cable_lock);
ucontrol->value.integer.value[0] = ucontrol->value.integer.value[0] =
loopback->setup[kcontrol->id.subdevice] loopback->setup[kcontrol->id.subdevice]
[kcontrol->id.device].channels; [kcontrol->id.device].channels;
mutex_unlock(&loopback->cable_lock);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment