Skip to content

Commit e190161

Browse files
committed
ALSA: pcm: Fix tight loop of OSS capture stream
When the trigger=off is passed for a PCM OSS stream, it sets the start_threshold of the given substream to the boundary size, so that it won't be automatically started. This can be problematic for a capture stream, unfortunately, as detected by syzkaller. The scenario is like the following: - In __snd_pcm_lib_xfer() that is invoked from snd_pcm_oss_read() loop, we have a check whether the stream was already started or the stream can be auto-started. - The function at this check returns 0 with trigger=off since we explicitly disable the auto-start. - The loop continues and repeats calling __snd_pcm_lib_xfer() tightly, which may lead to an RCU stall. This patch fixes the bug by simply allowing the wait for non-started stream in the case of OSS capture. For native usages, it's supposed to be done by the caller side (which is user-space), hence it returns zero like before. (In theory, __snd_pcm_lib_xfer() could wait even for the native API usage cases, too; but I'd like to stay in a safer side for not breaking the existing stuff for now.) Reported-by: syzbot+fbe0496f92a0ce7b786c@syzkaller.appspotmail.com Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 9e69666 commit e190161

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

sound/core/pcm_lib.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2112,6 +2112,13 @@ int pcm_lib_apply_appl_ptr(struct snd_pcm_substream *substream,
21122112
return 0;
21132113
}
21142114

2115+
/* allow waiting for a capture stream that hasn't been started */
2116+
#if IS_ENABLED(CONFIG_SND_PCM_OSS)
2117+
#define wait_capture_start(substream) ((substream)->oss.oss)
2118+
#else
2119+
#define wait_capture_start(substream) false
2120+
#endif
2121+
21152122
/* the common loop for read/write data */
21162123
snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
21172124
void *data, bool interleaved,
@@ -2182,7 +2189,7 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
21822189
err = snd_pcm_start(substream);
21832190
if (err < 0)
21842191
goto _end_unlock;
2185-
} else {
2192+
} else if (!wait_capture_start(substream)) {
21862193
/* nothing to do */
21872194
err = 0;
21882195
goto _end_unlock;

0 commit comments

Comments
 (0)