Skip to contentSkip to conversation

ASoC: SOF: control: reject out-of-range enum values

PATCH New Arnav Kapoor 1 participant 1 message Nov 18

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

PATCH v2 1/1 ASoC: SOF: control: reject out-of-range enum values

snd_sof_enum_put() passes the item indexes from user space to the IPC enum_put() op unchecked, and the IPC3 and IPC4 ops store them as they are and send them to the DSP. With the IPC4 sof-hda-generic-2ch.tplg on a Tiger Lake laptop, "Dmic0 Capture TDFB angle set enum" has 13 items but accepts 13 and 0xffffffff, and reads them back. The ALSA mixer-test selftest reports this as a write_invalid failure.

Reject indexes past the last item, as snd_soc_put_enum_double() does.

Fixes c3078f539704 ("ASoC: SOF: Add Sound Open Firmware KControl support")

---
Changes in v2:
- Only this patch (patch 4 of v1) is left.
- Drop the volume and switch range checks (v1 patches 1 and 2), which HyeongJun An's series covers:
https://lore.kernel.org/all/[email protected]/
This patch doesn't depend on that series.
- Drop "report volume changes in mixer steps" (v1 patch 3). Its commit message was wrong: the mixer-test event_spurious failures come from the out-of-range writes the test makes being accepted, so the range checks fix them. Writing back a volume right after the driver loads doesn't generate an event on this laptop with IPC3 or IPC4, so I have no case that needs that patch. Thanks to Mark for the review.

v1: https://lore.kernel.org/all/[email protected]/

Tested on a Lenovo V14 G2 ITL (Tiger Lake, 7.0.14 kernel, IPC4 sof-hda-generic-2ch.tplg): "Dmic0 Capture TDFB angle set enum" now rejects 13 and 0xffffffff with -EINVAL, and its mixer-test write_invalid failure is gone.

 sound/soc/sof/control.c | 5 +++++
 1 file changed, 5 insertions(+)
sound/soc/sof/control.c +5 -0
index 74d997a4f620..625a17624f41 100644
@@ -120,6 +120,11 @@ int snd_sof_enum_put(struct snd_kcontrol *kcontrol,
 	struct snd_soc_component *scomp = scontrol->scomp;
 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
 	const struct sof_ipc_tplg_ops *tplg_ops = sof_ipc_get_ops(sdev, tplg);
+	unsigned int i;
+
+	for (i = 0; i < scontrol->num_channels; i++)
+		if (ucontrol->value.enumerated.item[i] >= se->items)
+			return -EINVAL;
 
 	if (tplg_ops && tplg_ops->control && tplg_ops->control->enum_put)
 		return tplg_ops->control->enum_put(scontrol, ucontrol);

base-commit: fcfcd6db32adbdfe81c1ded257200e3ea6815d9a

Signature · 1 line
2.53.0