mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: linux-sound@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] ASoC: codecs: hda: Stop unsol events and jack polling before codec removal
Date: Wed,  7 Oct 2026 23:56:47 +0200	[thread overview]
Message-ID: <20261007215650.159871-3-tiwai@suse.de> (raw)
In-Reply-To: <20261007215650.159871-1-tiwai@suse.de>

The ASoC HD-audio codec driver has the same race as the legacy HDA
codec driver unbind: hda_codec_remove() calls the codec's remove
callback that releases the driver resources, followed by
snd_hda_codec_cleanup_for_unbind(), while the unsolicited event work
and the jack polling work may still run concurrently and access the
released resources, leading to a UAF.

Apply the same fix as done for the legacy driver: call
snd_hdac_device_disable_unsol() and cancel jackpoll_work at the
beginning of hda_codec_remove(), and clear the unsol_disabled flag
again at hda_codec_probe() so that the events get delivered after the
codec is re-registered.

Assisted-by: LLM
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/soc/codecs/hda.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/sound/soc/codecs/hda.c b/sound/soc/codecs/hda.c
index 237b0b060457..5188c9d74c8b 100644
--- a/sound/soc/codecs/hda.c
+++ b/sound/soc/codecs/hda.c
@@ -218,6 +218,9 @@ static int hda_codec_probe(struct snd_soc_component *component)
 		goto err;
 	}
 
+	/* unsol events are still blocked until registered */
+	codec->core.unsol_disabled = false;
+
 	ret = driver->ops->probe(codec, codec->preset);
 	if (ret < 0) {
 		dev_err(&hdev->dev, "codec init failed: %d\n", ret);
@@ -276,6 +279,10 @@ static void hda_codec_remove(struct snd_soc_component *component)
 	/* Don't allow any more runtime suspends */
 	pm_runtime_forbid(&hdev->dev);
 
+	/* stop asynchronous jack handling before freeing driver resources */
+	snd_hdac_device_disable_unsol(hdev);
+	cancel_delayed_work_sync(&codec->jackpoll_work);
+
 	hda_codec_unregister_dais(codec, component);
 
 	if (driver->ops->remove)
-- 
2.55.0


  parent reply	other threads:[~2026-10-07 21:56 UTC|newest]

Thread overview: 8+ 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
2026-10-08 11:52       ` Cezary Rojewski
2026-10-08 12:01         ` Takashi Iwai
2026-10-07 21:56 ` Takashi Iwai [this message]
2026-10-07 21:56 ` [PATCH 3/3] ALSA: hda: Make hdac_device.registered a plain bool 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=20261007215650.159871-3-tiwai@suse.de \
    --to=tiwai@suse.de \
    --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®