From: Takashi Iwai <tiwai@suse.de>
To: Cen Zhang <zzzccc427@gmail.com>
Cc: perex@perex.cz, tiwai@suse.com, linux-sound@vger.kernel.org,
linux-kernel@vger.kernel.org, tiwai@suse.de,
baijiaju1990@gmail.com, jjzuming@gmail.com
Subject: Re: [PATCH v3 1/2] ALSA: pcm: Protect the unregister notifier traversal
Date: Mon, 19 Oct 2026 10:13:28 +0200 [thread overview]
Message-ID: <87ld7uaz13.wl-tiwai@suse.de> (raw)
In-Reply-To: <pm-pmb-26d66390a25fec9fad6c-v6-5be251a3ac8832955a31-1@gmail.com>
On Sun, 18 Oct 2026 16:07:26 +0200,
Cen Zhang wrote:
>
> snd_pcm_free() traverses snd_pcm_notify_list and calls n_unregister
> without register_mutex, although snd_pcm_notify() takes that mutex to
> add and remove notifiers. PCM disconnect releases the mutex before the
> free callback runs, so it does not protect this later traversal.
>
> With no open OSS file, normal snd-pcm-oss removal can overlap PCM card
> teardown, for example when unbinding snd-dummy:
>
> PCM card teardown snd-pcm-oss unload
> ----------------- ------------------
> snd_pcm_dev_disconnect()
> remove PCM under register_mutex
> unlock register_mutex
> snd_pcm_free()
> fetch notifier
> snd_pcm_notify(..., 1)
> unlink notifier under mutex
> free module storage
> read notifier->n_unregister
> invoke callback
>
> The free path can then read the notifier from released module storage
> or call its unloaded code.
>
> Hold register_mutex across the unregister traversal and its callbacks.
> Notifier removal must wait until both have finished. This also protects
> the traversal if a callback releases the last module reference: module
> exit cannot unlink its notifier until the free path releases the mutex.
> Drop the mutex before private_free and the remaining stream cleanup.
>
> Fixes: c461482c8072 ("[ALSA] Unregister device files at disconnection")
> Assisted-by: LLM
> Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
Applied both patches to for-next branch now. Thanks.
Takashi
next prev parent reply other threads:[~2026-10-19 8:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-18 14:07 [PATCH v3 0/2] ALSA: Fix OSS teardown lifetime handling Cen Zhang
2026-10-18 14:07 ` [PATCH v3 1/2] ALSA: pcm: Protect the unregister notifier traversal Cen Zhang
2026-10-19 8:13 ` Takashi Iwai [this message]
2026-10-18 14:07 ` [PATCH v3 2/2] ALSA: oss: Keep emulation modules loaded until object teardown Cen Zhang
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=87ld7uaz13.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=baijiaju1990@gmail.com \
--cc=jjzuming@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
--cc=zzzccc427@gmail.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
all inboxes | Powered by JetHome®