Skip to content

Commit 0bb5579

Browse files
tiwaigregkh
authored andcommitted
ALSA: pcm: Fix UAF at PCM release via PCM timer access
commit a820ccb upstream. The PCM runtime object is created and freed dynamically at PCM stream open / close time. This is tracked via substream->runtime, and it's cleared at snd_pcm_detach_substream(). The runtime object assignment is protected by PCM open_mutex, so for all PCM operations, it's safely handled. However, each PCM substream provides also an ALSA timer interface, and user-space can access to this while closing a PCM substream. This may eventually lead to a UAF, as snd_pcm_timer_resolution() tries to access the runtime while clearing it in other side. Fortunately, it's the only concurrent access from the PCM timer, and it merely reads runtime->timer_resolution field. So, we can avoid the race by reordering kfree() and wrapping the substream->runtime clearance with the corresponding timer lock. Reported-by: syzbot+8e62ff4e07aa2ce87826@syzkaller.appspotmail.com Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d3b14a6 commit 0bb5579

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎sound/core/pcm.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <sound/core.h>
2929
#include <sound/minors.h>
3030
#include <sound/pcm.h>
31+
#include <sound/timer.h>
3132
#include <sound/control.h>
3233
#include <sound/info.h>
3334

@@ -1050,8 +1051,13 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream)
10501051
snd_free_pages((void*)runtime->control,
10511052
PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control)));
10521053
kfree(runtime->hw_constraints.rules);
1053-
kfree(runtime);
1054+
/* Avoid concurrent access to runtime via PCM timer interface */
1055+
if (substream->timer)
1056+
spin_lock_irq(&substream->timer->lock);
10541057
substream->runtime = NULL;
1058+
if (substream->timer)
1059+
spin_unlock_irq(&substream->timer->lock);
1060+
kfree(runtime);
10551061
put_pid(substream->pid);
10561062
substream->pid = NULL;
10571063
substream->pstr->substream_opened--;

0 commit comments

Comments
 (0)