Skip to content

Commit ac3e9b5

Browse files
tiwaigregkh
authored andcommitted
ALSA: pcm: oss: Fix data race at accessing runtime.oss.trigger
commit 901ac0f upstream. Currently the runtime.oss.trigger field may be accessed concurrently without protection, which may lead to the data race. And, in this case, it may lead to more severe problem because it's a bit field; as writing the data, it may overwrite other bit fields as well, which confuses the operation completely, as spotted by fuzzing. Fix it by covering runtime.oss.trigger bit fled also with the existing params_lock mutex in both snd_pcm_oss_get_trigger() and snd_pcm_oss_poll(). Reported-and-tested-by: Jaeyoung Chung <jjy600901@snu.ac.kr> Closes: https://lore.kernel.org/20260423145330.210035-1-jjy600901@snu.ac.kr Cc: <stable@vger.kernel.org> Link: https://patch.msgid.link/20260424112205.123703-1-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f8ad9ef commit ac3e9b5

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

sound/core/oss/pcm_oss.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,10 +2146,16 @@ static int snd_pcm_oss_get_trigger(struct snd_pcm_oss_file *pcm_oss_file)
21462146

21472147
psubstream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK];
21482148
csubstream = pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE];
2149-
if (psubstream && psubstream->runtime && psubstream->runtime->oss.trigger)
2150-
result |= PCM_ENABLE_OUTPUT;
2151-
if (csubstream && csubstream->runtime && csubstream->runtime->oss.trigger)
2152-
result |= PCM_ENABLE_INPUT;
2149+
if (psubstream && psubstream->runtime) {
2150+
guard(mutex)(&psubstream->runtime->oss.params_lock);
2151+
if (psubstream->runtime->oss.trigger)
2152+
result |= PCM_ENABLE_OUTPUT;
2153+
}
2154+
if (csubstream && csubstream->runtime) {
2155+
guard(mutex)(&csubstream->runtime->oss.params_lock);
2156+
if (csubstream->runtime->oss.trigger)
2157+
result |= PCM_ENABLE_INPUT;
2158+
}
21532159
return result;
21542160
}
21552161

@@ -2823,6 +2829,17 @@ static int snd_pcm_oss_capture_ready(struct snd_pcm_substream *substream)
28232829
runtime->oss.period_frames;
28242830
}
28252831

2832+
static bool need_input_retrigger(struct snd_pcm_runtime *runtime)
2833+
{
2834+
bool ret;
2835+
2836+
guard(mutex)(&runtime->oss.params_lock);
2837+
ret = runtime->oss.trigger;
2838+
if (ret)
2839+
runtime->oss.trigger = 0;
2840+
return ret;
2841+
}
2842+
28262843
static __poll_t snd_pcm_oss_poll(struct file *file, poll_table * wait)
28272844
{
28282845
struct snd_pcm_oss_file *pcm_oss_file;
@@ -2855,11 +2872,11 @@ static __poll_t snd_pcm_oss_poll(struct file *file, poll_table * wait)
28552872
snd_pcm_oss_capture_ready(csubstream))
28562873
mask |= EPOLLIN | EPOLLRDNORM;
28572874
}
2858-
if (ostate != SNDRV_PCM_STATE_RUNNING && runtime->oss.trigger) {
2875+
if (ostate != SNDRV_PCM_STATE_RUNNING &&
2876+
need_input_retrigger(runtime)) {
28592877
struct snd_pcm_oss_file ofile;
28602878
memset(&ofile, 0, sizeof(ofile));
28612879
ofile.streams[SNDRV_PCM_STREAM_CAPTURE] = pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE];
2862-
runtime->oss.trigger = 0;
28632880
snd_pcm_oss_set_trigger(&ofile, PCM_ENABLE_INPUT);
28642881
}
28652882
}

0 commit comments

Comments
 (0)