From: Takashi Iwai <tiwai@suse.de>
To: Cezary Rojewski <cezary.rojewski@intel.com>
Cc: Takashi Iwai <tiwai@suse.de>, <linux-kernel@vger.kernel.org>,
<linux-sound@vger.kernel.org>
Subject: Re: [PATCH 1/3] ALSA: hda: Stop unsol events and jack polling before codec unbind
Date: Thu, 08 Oct 2026 12:16:41 +0200 [thread overview]
Message-ID: <87ik3c5wfq.wl-tiwai@suse.de> (raw)
In-Reply-To: <7efc9ca8-b470-410c-b717-3c548bd196f1@intel.com>
On Thu, 08 Oct 2026 11:08:13 +0200,
Cezary Rojewski wrote:
>
> On 10/7/2026 11:56 PM, Takashi Iwai wrote:
> > At unbinding a codec driver, hda_codec_driver_remove() calls the
> > codec's remove callback that releases the driver resources, followed
> > by snd_hda_codec_cleanup_for_unbind(). Meanwhile, the unsolicited
> > events are processed asynchronously in bus->unsol_work, and
> > snd_hdac_bus_process_unsol_events() checks only codec->registered flag
> > before calling the driver's unsol_event callback without the lock.
> > Since codec->registered is cleared only in
> > snd_hda_codec_cleanup_for_unbind(), and there is no flush of the unsol
> > work at unbinding, the unsol event handler may run concurrently during
> > the running remove callback, which may lead to a UAF. The same
> > problem applies to the jack polling work, which is canceled only after
> > the remove callback.
>
> > +++ b/sound/hda/common/bind.c
> > @@ -100,6 +100,9 @@ static int hda_codec_driver_probe(struct device *dev)
> > if (WARN_ON(!codec->preset))
> > return -EINVAL;
> >
> > + /* unsol events are still blocked until registered */
> > + codec->core.unsol_disabled = false;
> > +
> > err = snd_hda_codec_set_name(codec, codec->preset->name);
> > if (err < 0)
> > goto error;
> > @@ -160,6 +163,10 @@ static int hda_codec_driver_remove(struct device *dev)
> > return codec->bus->core.ext_ops->hdev_detach(&codec->core);
> > }
> >
> > + /* stop asynchronous jack handling before freeing driver resources */
> > + snd_hdac_device_disable_unsol(&codec->core);
> > + cancel_delayed_work_sync(&codec->jackpoll_work);
>
>
> IMHO this is a proof that ->registered flag doesn't do its job.
> snd_hda_codec_cleanup_for_unbind() is called right after and it does
> contain cancel_delayed_work_sync(&codec->jackpoll_work). It does
> contain snd_hda_codec_disconnect_pcms() and
> snd_hda_jack_tbl_disconnect() operations too.
It's about the pending works, and the flag doesn't help there alone
unless they are synchronized; at the time point you flip the flag, the
work might be already in-flight, so the flag switch may miss the
chances.
> I'd say it is snd_hda_codec_cleanup_for_unbind() that needs an update
> and perhaps be responsible for calling driver->remove() too.
Yeah, some code reorganization would be good.
thanks,
Takashi
next prev parent reply other threads:[~2026-10-08 10:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-07 21:56 [PATCH 0/3] ALSA/ASoC: hda: Fix race between unsol events and unbind Takashi Iwai
2026-10-07 21:56 ` [PATCH 1/3] ALSA: hda: Stop unsol events and jack polling before codec unbind Takashi Iwai
2026-10-08 9:08 ` Cezary Rojewski
2026-10-08 10:16 ` Takashi Iwai [this message]
2026-10-08 11:52 ` Cezary Rojewski
2026-10-08 12:01 ` Takashi Iwai
2026-10-07 21:56 ` [PATCH 2/3] ASoC: codecs: hda: Stop unsol events and jack polling before codec removal Takashi Iwai
2026-10-07 21:56 ` [PATCH 3/3] ALSA: hda: Make hdac_device.registered a plain bool Takashi Iwai
2026-10-09 7:44 ` [PATCH 0/3] ALSA/ASoC: hda: Fix race between unsol events and unbind Cezary Rojewski
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=87ik3c5wfq.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=cezary.rojewski@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
/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®