Skip to contentSkip to conversation

ASoC: SOF: Intel: hda: Fix NULL deref in hw_params and hw_free

PATCH In review Chen Yuxi 2 participants 2 messages Nov 19 – Nov 26

Subsystems (4)
lore
Share & tools
lore

Chen Yuxi

author
#0 lore raw

PATCH 1/1 ASoC: SOF: Intel: hda: Fix NULL deref in hw_params and hw_free

When the topology and the machine driver DAI links do not match, the DAI widget may be missing and hda_dai_get_ops() returns NULL. However, in hda_dai_hw_params_data() and hda_dai_hw_free(), the sdev pointer is obtained by dereferencing the DAI widget at declaration time, before the ops check, so a NULL widget is dereferenced before the intended error path can run.

Move both sdev assignments after the ops check. Also use dai->dev instead of sdev->dev for the error message in hda_dai_hw_params_data(), since sdev cannot be obtained when the DAI widget is missing.

Fixes de8e2d5d8024 ("ASoC: SOF: Intel: hda-dai: remove use of cpu_dai->component drvdata")
---
 sound/soc/sof/intel/hda-dai.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
sound/soc/sof/intel/hda-dai.c +7 -3
index 7d920d43ef2a..987a4deeee28 100644
@@ -223,13 +223,15 @@ static int __maybe_unused hda_dai_hw_free(struct snd_pcm_substream *substream,
 {
 	const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, cpu_dai);
 	struct hdac_ext_stream *hext_stream;
-	struct snd_sof_dev *sdev = dai_to_sdev(substream, cpu_dai);
+	struct snd_sof_dev *sdev;
 
 	if (!ops) {
 		dev_err(cpu_dai->dev, "DAI widget ops not set\n");
 		return -EINVAL;
 	}
 
+	sdev = dai_to_sdev(substream, cpu_dai);
+
 	hext_stream = ops->get_hext_stream(sdev, cpu_dai, substream);
 	if (!hext_stream)
 		return 0;
@@ -246,14 +248,16 @@ static int __maybe_unused hda_dai_hw_params_data(struct snd_pcm_substream *subst
 	struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(dai, substream->stream);
 	const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, dai);
 	struct hdac_ext_stream *hext_stream;
-	struct snd_sof_dev *sdev = widget_to_sdev(w);
+	struct snd_sof_dev *sdev;
 	int ret;
 
 	if (!ops) {
-		dev_err(sdev->dev, "DAI widget ops not set\n");
+		dev_err(dai->dev, "DAI widget ops not set\n");
 		return -EINVAL;
 	}
 
+	sdev = widget_to_sdev(w);
+
 	hext_stream = ops->get_hext_stream(sdev, dai, substream);
 	if (hext_stream && hext_stream->link_prepared)
 		return 0;
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 1 line · Chen Yuxi

ASoC: SOF: Intel: hda: Fix NULL deref in hw_params and hw_free

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.5

Thanks!

[1/1] ASoC: SOF: Intel: hda: Fix NULL deref in hw_params and hw_free

      https://git.kernel.org/broonie/sound/c/4c30a6661e53

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark