[PATCH 1/4] ASoC: SOF: control: reject out-of-range volume values

From: Arnav Kapoor

Date: Tue Nov 17 2026 - 06:00:12 EST


snd_sof_volume_put() passes the values from user space to the IPC
volume_put() op without checking them. The IPC3 and IPC4 ops convert
each value with mixer_to_ipc(), which takes an unsigned int and clamps
anything past the end of the volume table to its last entry. A negative
value therefore sets the volume to the maximum: on a Tiger Lake laptop
with sof-hda-generic-2ch.tplg, writing -1 to "PGA2.0 2 Master Capture
Volume" (0..80, set to 50) succeeds and reads back 80.

Reject values outside 0..max, as the ALSA control API expects, before
calling the op.

Fixes: c3078f539704 ("ASoC: SOF: Add Sound Open Firmware KControl support")
Signed-off-by: Arnav Kapoor <kapoorarnav43@xxxxxxxxx>
---
sound/soc/sof/control.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/sound/soc/sof/control.c b/sound/soc/sof/control.c
index 74d997a4f620..02cf59bf1f95 100644
--- a/sound/soc/sof/control.c
+++ b/sound/soc/sof/control.c
@@ -15,6 +15,21 @@
#include "sof-priv.h"
#include "sof-audio.h"

+static bool snd_sof_values_in_range(const struct snd_sof_control *scontrol,
+ const struct snd_ctl_elem_value *ucontrol)
+{
+ unsigned int i;
+
+ for (i = 0; i < scontrol->num_channels; i++) {
+ long value = ucontrol->value.integer.value[i];
+
+ if (value < 0 || value > scontrol->max)
+ return false;
+ }
+
+ return true;
+}
+
int snd_sof_volume_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
@@ -39,6 +54,9 @@ int snd_sof_volume_put(struct snd_kcontrol *kcontrol,
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);

+ if (!snd_sof_values_in_range(scontrol, ucontrol))
+ return -EINVAL;
+
if (tplg_ops && tplg_ops->control && tplg_ops->control->volume_put)
return tplg_ops->control->volume_put(scontrol, ucontrol);

--
2.53.0