public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: SDCA: Fix NULL pointer dereference in sdca_jack_process()
@ 2026-03-10 18:38 gaggery.tsai
  2026-03-11 16:31 ` Mark Brown
  2026-03-12 14:32 ` [PATCH v2] " gaggery.tsai
  0 siblings, 2 replies; 9+ messages in thread
From: gaggery.tsai @ 2026-03-10 18:38 UTC (permalink / raw)
  To: linux-sound, patches
  Cc: ckeepax, mstrozek, yung-chuan.liao, pierre-louis.bossart, broonie,
	TsaiGaggery, stable

From: TsaiGaggery <gaggery.tsai@intel.com>

sdca_jack_process() unconditionally dereferences component->card and
card->snd_card at the top of the function. This causes a NULL pointer
dereference when the SDCA IRQ handler fires after the ASoC card has
been torn down.

The crash occurs deterministically on platforms where snd_soc_bind_card()
fails (e.g. due to missing machine driver support). The sequence is:

  1. soc_probe_component() sets component->card and calls
     snd_soc_component_probe(), which registers the SDCA IRQ handler
     via sdca_irq_populate() / devm_request_threaded_irq().

  2. snd_soc_bind_card() fails (e.g. sof_sdw returns -ENOTSUPP when
     no matching machine driver is found for the codec configuration).

  3. soc_cleanup_card_resources() -> soc_remove_component() sets
     component->card = NULL.

  4. The SDCA IRQ handler remains registered because it is tied to
     device lifetime (devm), not card lifetime.

  5. A subsequent SoundWire alert fires via
     cdns_update_slave_status_work() -> sdw_handle_slave_status() ->
     handle_nested_irq() -> detected_mode_handler() ->
     sdca_jack_process(), which dereferences the now-NULL
     component->card, causing the crash at offset 0xa0
     (offsetof(struct snd_soc_card, snd_card)).

  BUG: kernel NULL pointer dereference, address: 00000000000000a0
  RIP: 0010:sdca_jack_process+0x47/0x470 [snd_soc_sdca]
  Call Trace:
   detected_mode_handler+0x2e/0x70 [snd_soc_sdca]
   handle_nested_irq+0xa9/0x120
   regmap_irq_thread+0x1d5/0x320
   handle_nested_irq+0xa9/0x120
   sdw_handle_slave_status+0xe92/0x17d0 [soundwire_bus]
   cdns_update_slave_status_work+0x25e/0x470 [soundwire_cadence]

Fix this by deferring the rwsem and kctl initialization until after
a NULL check on card and card->snd_card, returning -ENODEV if the
card is not available. This is consistent with the same defensive
pattern used by existing SDCA codec drivers (e.g. rt721-sdca.c,
rt712-sdca.c).

Tested on Intel Panther Lake with Cirrus Logic CS42L45/CS35L57
SoundWire codecs. The crash reproduces reliably when
snd_soc_bind_card() fails and can be triggered by any unsupported
codec configuration that causes card registration to return an error.

Fixes: 82e12800f563 ("ASoC: SDCA: Add ability to connect SDCA jacks to ASoC jacks")
Cc: stable@vger.kernel.org
Cc: Charles Keepax <ckeepax@opensource.cirrus.com>
Cc: Maciej Strozek <mstrozek@opensource.cirrus.com>
Cc: Bard Liao <yung-chuan.liao@linux.intel.com>
Cc: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>
Signed-off-by: Gaggery Tsai <gaggery.tsai@intel.com>
---
 sound/soc/sdca/sdca_jack.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/sound/soc/sdca/sdca_jack.c b/sound/soc/sdca/sdca_jack.c
index 49d317d3b8c8..b52d88a08634 100644
--- a/sound/soc/sdca/sdca_jack.c
+++ b/sound/soc/sdca/sdca_jack.c
@@ -37,13 +37,21 @@ int sdca_jack_process(struct sdca_interrupt *interrupt)
 	struct device *dev = interrupt->dev;
 	struct snd_soc_component *component = interrupt->component;
 	struct snd_soc_card *card = component->card;
-	struct rw_semaphore *rwsem = &card->snd_card->controls_rwsem;
+	struct rw_semaphore *rwsem;
 	struct jack_state *state = interrupt->priv;
-	struct snd_kcontrol *kctl = state->kctl;
+	struct snd_kcontrol *kctl;
 	struct snd_ctl_elem_value *ucontrol __free(kfree) = NULL;
 	unsigned int reg, val;
 	int ret;
 
+	if (!card || !card->snd_card) {
+		dev_dbg(dev, "card not yet bound, deferring jack event\n");
+		return -ENODEV;
+	}
+
+	rwsem = &card->snd_card->controls_rwsem;
+	kctl = state->kctl;
+
 	guard(rwsem_write)(rwsem);
 
 	if (!kctl) {
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-03-13 14:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-10 18:38 [PATCH] ASoC: SDCA: Fix NULL pointer dereference in sdca_jack_process() gaggery.tsai
2026-03-11 16:31 ` Mark Brown
2026-03-11 17:45   ` Tsai, Gaggery
2026-03-11 17:50     ` Charles Keepax
2026-03-12 14:32 ` [PATCH v2] " gaggery.tsai
2026-03-12 17:32   ` Mark Brown
2026-03-13  9:54   ` Charles Keepax
2026-03-13 13:28     ` Mark Brown
2026-03-13 14:28       ` Charles Keepax

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox