mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] ASoC: SOF: control: reject out-of-range enum values
@ 2026-11-18 10:31 Arnav Kapoor
  0 siblings, 0 replies; only message in thread
From: Arnav Kapoor @ 2026-11-18 10:31 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Peter Ujfalusi, Bard Liao, Daniel Baluta
  Cc: Ranjani Sridharan, Kai Vehmanen, Pierre-Louis Bossart,
	Jaroslav Kysela, Takashi Iwai, HyeongJun An, sound-open-firmware,
	linux-sound, linux-kernel, Arnav Kapoor

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")
Signed-off-by: Arnav Kapoor <kapoorarnav43@gmail.com>
---
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/20261118093840.3514408-1-sammiee5311@gmail.com/
  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/20261117105953.188645-1-kapoorarnav43@gmail.com/

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(+)

diff --git a/sound/soc/sof/control.c b/sound/soc/sof/control.c
index 74d997a4f620..625a17624f41 100644
--- a/sound/soc/sof/control.c
+++ b/sound/soc/sof/control.c
@@ -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
-- 
2.53.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-18 10:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 10:31 [PATCH v2] ASoC: SOF: control: reject out-of-range enum values Arnav Kapoor

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®