Skip to contentSkip to conversation

ASoC: dapm: fix out-of-bounds accesses to DAPM lookup tables

PATCH In review Pierre-Louis Bossart 2 participants 3 messages Feb 5, 2019 – Feb 6, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/2 ASoC: dapm: fix out-of-bounds accesses to DAPM lookup tables

KASAN reports and additional traces point to out-of-bounds accesses to the dapm_up_seq and dapm_down_seq lookup tables. The indices used are larger than the array definition.

Fix by adding missing entries for the new widget types in these two lookup tables, and align them with PGA values.

Also the sequences for the following widgets were not defined. Since their values defaulted to zero, assign them explicitly

snd_soc_dapm_input
snd_soc_dapm_output
snd_soc_dapm_vmid
snd_soc_dapm_siggen
snd_soc_dapm_sink

Fixes 8a70b4544ef4 ('ASoC: dapm: Add new widget type for constructing DAPM graphs on DSPs.').
---
 sound/soc/soc-dapm.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
sound/soc/soc-dapm.c +24 -0
index 5b74dffc9c11..2bf5bab579de 100644
@@ -70,12 +70,16 @@ static int dapm_up_seq[] = {
 	[snd_soc_dapm_clock_supply] = 1,
 	[snd_soc_dapm_supply] = 2,
 	[snd_soc_dapm_micbias] = 3,
+	[snd_soc_dapm_vmid] = 3,
 	[snd_soc_dapm_dai_link] = 2,
 	[snd_soc_dapm_dai_in] = 4,
 	[snd_soc_dapm_dai_out] = 4,
 	[snd_soc_dapm_aif_in] = 4,
 	[snd_soc_dapm_aif_out] = 4,
 	[snd_soc_dapm_mic] = 5,
+	[snd_soc_dapm_siggen] = 5,
+	[snd_soc_dapm_input] = 5,
+	[snd_soc_dapm_output] = 5,
 	[snd_soc_dapm_mux] = 6,
 	[snd_soc_dapm_demux] = 6,
 	[snd_soc_dapm_dac] = 7,
@@ -83,11 +87,19 @@ static int dapm_up_seq[] = {
 	[snd_soc_dapm_mixer] = 8,
 	[snd_soc_dapm_mixer_named_ctl] = 8,
 	[snd_soc_dapm_pga] = 9,
+	[snd_soc_dapm_buffer] = 9,
+	[snd_soc_dapm_scheduler] = 9,
+	[snd_soc_dapm_effect] = 9,
+	[snd_soc_dapm_src] = 9,
+	[snd_soc_dapm_asrc] = 9,
+	[snd_soc_dapm_encoder] = 9,
+	[snd_soc_dapm_decoder] = 9,
 	[snd_soc_dapm_adc] = 10,
 	[snd_soc_dapm_out_drv] = 11,
 	[snd_soc_dapm_hp] = 11,
 	[snd_soc_dapm_spk] = 11,
 	[snd_soc_dapm_line] = 11,
+	[snd_soc_dapm_sink] = 11,
 	[snd_soc_dapm_kcontrol] = 12,
 	[snd_soc_dapm_post] = 13,
 };
@@ -100,13 +112,25 @@ static int dapm_down_seq[] = {
 	[snd_soc_dapm_spk] = 3,
 	[snd_soc_dapm_line] = 3,
 	[snd_soc_dapm_out_drv] = 3,
+	[snd_soc_dapm_sink] = 3,
 	[snd_soc_dapm_pga] = 4,
+	[snd_soc_dapm_buffer] = 4,
+	[snd_soc_dapm_scheduler] = 4,
+	[snd_soc_dapm_effect] = 4,
+	[snd_soc_dapm_src] = 4,
+	[snd_soc_dapm_asrc] = 4,
+	[snd_soc_dapm_encoder] = 4,
+	[snd_soc_dapm_decoder] = 4,
 	[snd_soc_dapm_switch] = 5,
 	[snd_soc_dapm_mixer_named_ctl] = 5,
 	[snd_soc_dapm_mixer] = 5,
 	[snd_soc_dapm_dac] = 6,
 	[snd_soc_dapm_mic] = 7,
+	[snd_soc_dapm_siggen] = 7,
+	[snd_soc_dapm_input] = 7,
+	[snd_soc_dapm_output] = 7,
 	[snd_soc_dapm_micbias] = 8,
+	[snd_soc_dapm_vmid] = 8,
 	[snd_soc_dapm_mux] = 9,
 	[snd_soc_dapm_demux] = 9,
 	[snd_soc_dapm_aif_in] = 10,
Signature · 1 line
2.17.1
#1 lore raw

PATCH v4 2/2 ASoC: dapm: harden use of lookup tables

To detect potential errors, let's add:

a) build-time warnings when the table size isn't aligned with the enum list
b) run-time warnings when the values are not initialized. This requires an increase by one of all values to avoid the default 0.

---
 include/sound/soc-dapm.h |   3 +
 sound/soc/soc-dapm.c     | 158 ++++++++++++++++++++-------------------
 2 files changed, 85 insertions(+), 76 deletions(-)
include/sound/soc-dapm.h +3 -0
index 79b4ddfb8e9e..c00a0b8ade08 100644
@@ -523,6 +523,9 @@ enum snd_soc_dapm_type {
 	snd_soc_dapm_asrc,		/* DSP/CODEC ASRC component */
 	snd_soc_dapm_encoder,		/* FW/SW audio encoder component */
 	snd_soc_dapm_decoder,		/* FW/SW audio decoder component */
+
+	/* Don't edit below this line */
+	SND_SOC_DAPM_TYPE_COUNT
 };
 
 enum snd_soc_dapm_subclass {
sound/soc/soc-dapm.c +82 -76

178 lines not on this page · raw message

Signature · 1 line
2.17.1
maintainer
#2 lore raw

Applied "ASoC: dapm: harden use of lookup tables" to the asoc tree

The patch

ASoC: dapm: harden use of lookup tables

has been applied to the asoc tree at

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

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

Quoted 1 line

From f13d4b5f85e1c436c9bf21205509266b5a81a320 Mon Sep 17 00:00:00 2001

From: Pierre-Louis Bossart <[email protected]>
Date: Tue, 5 Feb 2019 10:22:28 -0600
Subject: [PATCH] ASoC: dapm: harden use of lookup tables

To detect potential errors, let's add:

a) build-time warnings when the table size isn't aligned with the enum list
b) run-time warnings when the values are not initialized. This requires an increase by one of all values to avoid the default 0.

---
 include/sound/soc-dapm.h |   3 +
 sound/soc/soc-dapm.c     | 158 ++++++++++++++++++++-------------------
 2 files changed, 85 insertions(+), 76 deletions(-)
include/sound/soc-dapm.h +3 -0
index 79b4ddfb8e9e..c00a0b8ade08 100644
@@ -523,6 +523,9 @@ enum snd_soc_dapm_type {
 	snd_soc_dapm_asrc,		/* DSP/CODEC ASRC component */
 	snd_soc_dapm_encoder,		/* FW/SW audio encoder component */
 	snd_soc_dapm_decoder,		/* FW/SW audio decoder component */
+
+	/* Don't edit below this line */
+	SND_SOC_DAPM_TYPE_COUNT
 };
 
 enum snd_soc_dapm_subclass {
sound/soc/soc-dapm.c +82 -76

178 lines not on this page · raw message

Signature · 1 line
2.20.1