Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Cezary Rojewski <cezary.rojewski@intel.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: <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, 8 Oct 2026 11:08:13 +0200	[thread overview]
Message-ID: <7efc9ca8-b470-410c-b717-3c548bd196f1@intel.com> (raw)
In-Reply-To: <20261007215650.159871-2-tiwai@suse.de>

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.

I'd say it is snd_hda_codec_cleanup_for_unbind() that needs an update
and perhaps be responsible for calling driver->remove() too.

> +
>  	snd_hda_codec_disconnect_pcms(codec);
>  	snd_hda_jack_tbl_disconnect(codec);
>  	snd_refcount_sync(&codec->pcm_ref);

  reply	other threads:[~2026-10-08  9:08 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 [this message]
2026-10-08 10:16     ` Takashi Iwai
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=7efc9ca8-b470-410c-b717-3c548bd196f1@intel.com \
    --to=cezary.rojewski@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=tiwai@suse.de \
    /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