From: Takashi Iwai <tiwai@suse.de>
To: Mehul Rao <mehulrao@gmail.com>
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] ALSA: pcm: fix use-after-free on linked stream runtime in snd_pcm_drain()
Date: Mon, 09 Mar 2026 09:57:00 +0100 [thread overview]
Message-ID: <87qzpttm77.wl-tiwai@suse.de> (raw)
In-Reply-To: <20260305193508.311096-1-mehulrao@gmail.com>
On Thu, 05 Mar 2026 20:35:07 +0100,
Mehul Rao wrote:
>
> In the drain loop, the local variable 'runtime' is reassigned to a
> linked stream's runtime (runtime = s->runtime at line 2157). After
> releasing the stream lock at line 2169, the code accesses
> runtime->no_period_wakeup, runtime->rate, and runtime->buffer_size
> (lines 2170-2178) ― all referencing the linked stream's runtime without
> any lock or refcount protecting its lifetime.
>
> A concurrent close() on the linked stream's fd triggers
> snd_pcm_release_substream() → snd_pcm_drop() → pcm_release_private()
> → snd_pcm_unlink() → snd_pcm_detach_substream() → kfree(runtime).
> No synchronization prevents kfree(runtime) from completing while the
> drain path dereferences the stale pointer.
>
> Fix by caching the needed runtime fields (no_period_wakeup, rate,
> buffer_size) into local variables while still holding the stream lock,
> and using the cached values after the lock is released.
>
> Fixes: f2b3614cefb6 ("ALSA: PCM - Don't check DMA time-out too shortly")
> Cc: stable@vger.kernel.org
> Signed-off-by: Mehul Rao <mehulrao@gmail.com>
Do you have the actual crash by fuzzer or such? Or is it only
theoretical?
In anyway, I applied now as the fix looks fine and safe.
thanks,
Takashi
next prev parent reply other threads:[~2026-03-09 8:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-05 19:35 [PATCH] ALSA: pcm: fix use-after-free on linked stream runtime in snd_pcm_drain() Mehul Rao
2026-03-09 8:57 ` Takashi Iwai [this message]
[not found] ` <CAMNhdctTJYdzQvv1MtZtqUjYSjrtiu_6J6E9eQJSjx-wmXfWKg@mail.gmail.com>
2026-03-10 17:25 ` Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87qzpttm77.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=mehulrao@gmail.com \
--cc=perex@perex.cz \
--cc=stable@vger.kernel.org \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox