aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2018-04-02 16:41:43 -0400
committerTakashi Iwai <tiwai@suse.de>2018-04-03 02:36:40 -0400
commita820ccbe21e8ce8e86c39cd1d3bc8c7d1cbb949b (patch)
treee5b3fd50df32c9c9fa8b18f96079f5eb0a476888
parent903d271a3f83826ef810a4b5dbbd9842cf0465d6 (diff)
ALSA: pcm: Fix UAF at PCM release via PCM timer access
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>
-rw-r--r--sound/core/pcm.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index 09ee8c6b9f75..66ac89aad681 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -28,6 +28,7 @@
28#include <sound/core.h> 28#include <sound/core.h>
29#include <sound/minors.h> 29#include <sound/minors.h>
30#include <sound/pcm.h> 30#include <sound/pcm.h>
31#include <sound/timer.h>
31#include <sound/control.h> 32#include <sound/control.h>
32#include <sound/info.h> 33#include <sound/info.h>
33 34
@@ -1054,8 +1055,13 @@ void snd_pcm_detach_substream(struct snd_pcm_substream *substream)
1054 snd_free_pages((void*)runtime->control, 1055 snd_free_pages((void*)runtime->control,
1055 PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control))); 1056 PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control)));
1056 kfree(runtime->hw_constraints.rules); 1057 kfree(runtime->hw_constraints.rules);
1057 kfree(runtime); 1058 /* Avoid concurrent access to runtime via PCM timer interface */
1059 if (substream->timer)
1060 spin_lock_irq(&substream->timer->lock);
1058 substream->runtime = NULL; 1061 substream->runtime = NULL;
1062 if (substream->timer)
1063 spin_unlock_irq(&substream->timer->lock);
1064 kfree(runtime);
1059 put_pid(substream->pid); 1065 put_pid(substream->pid);
1060 substream->pid = NULL; 1066 substream->pid = NULL;
1061 substream->pstr->substream_opened--; 1067 substream->pstr->substream_opened--;