From: HyeongJun An <sammiee5311@gmail.com>
To: Mark Brown <broonie@kernel.org>
Cc: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Bard Liao <yung-chuan.liao@linux.intel.com>,
Daniel Baluta <daniel.baluta@nxp.com>,
Kai Vehmanen <kai.vehmanen@linux.intel.com>,
Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>,
Vijendar Mukunda <Vijendar.Mukunda@amd.com>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Arnav Kapoor <kapoorarnav43@gmail.com>,
sound-open-firmware@alsa-project.org,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
HyeongJun An <sammiee5311@gmail.com>
Subject: [PATCH v2 2/2] ASoC: SOF: control: Reject out of range volume and switch values
Date: Wed, 18 Nov 2026 18:38:40 +0900 [thread overview]
Message-ID: <20261118093840.3514408-3-sammiee5311@gmail.com> (raw)
In-Reply-To: <20261118093840.3514408-1-sammiee5311@gmail.com>
The snd_sof_volume_put() and snd_sof_switch_put() pass the user values
to the IPC put handlers without a range check. The switch handlers
store any value and send it to the firmware, so on IPC3 writing 2 or -1
to a switch reads back as 2 or 4294967295. The volume handlers convert
the value to u32 and clamp it to the end of the volume table. Writing -1
sets the maximum volume, and on 64-bit writing LONG_MIN sets the
minimum, both without an error.
Return -EINVAL for values outside the range the info callbacks report,
as snd_soc_put_volsw() does. This fixes the write_invalid failures in
mixer-test, and the event_spurious failures caused by the events those
writes generated.
Fixes: c3078f539704 ("ASoC: SOF: Add Sound Open Firmware KControl support")
Signed-off-by: HyeongJun An <sammiee5311@gmail.com>
---
sound/soc/sof/control.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/sound/soc/sof/control.c b/sound/soc/sof/control.c
index 136e2ce15201..dcf101f7e1d5 100644
--- a/sound/soc/sof/control.c
+++ b/sound/soc/sof/control.c
@@ -26,6 +26,24 @@ static int sof_mixer_max(const struct soc_mixer_control *sm)
return max;
}
+/* the IPC put handlers do not check the range */
+static int sof_mixer_check_values(const struct soc_mixer_control *sm,
+ const struct snd_sof_control *scontrol,
+ const struct snd_ctl_elem_value *ucontrol)
+{
+ int max = sof_mixer_max(sm);
+ unsigned int i;
+
+ for (i = 0; i < scontrol->num_channels; i++) {
+ long val = ucontrol->value.integer.value[i];
+
+ if (val < 0 || val > max)
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
int snd_sof_volume_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
@@ -49,6 +67,11 @@ int snd_sof_volume_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);
+ int ret;
+
+ ret = sof_mixer_check_values(sm, scontrol, ucontrol);
+ if (ret)
+ return ret;
if (tplg_ops && tplg_ops->control && tplg_ops->control->volume_put)
return tplg_ops->control->volume_put(scontrol, ucontrol);
@@ -97,6 +120,11 @@ int snd_sof_switch_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);
+ int ret;
+
+ ret = sof_mixer_check_values(sm, scontrol, ucontrol);
+ if (ret)
+ return ret;
if (tplg_ops && tplg_ops->control && tplg_ops->control->switch_put)
return tplg_ops->control->switch_put(scontrol, ucontrol);
--
2.43.0
prev parent reply other threads:[~2026-11-18 9:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 9:38 [PATCH v2 0/2] ASoC: SOF: control: Check the " HyeongJun An
2026-11-18 9:38 ` [PATCH v2 1/2] ASoC: SOF: control: Report the volume range as ASoC does HyeongJun An
2026-11-18 9:38 ` HyeongJun An [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118093840.3514408-3-sammiee5311@gmail.com \
--to=sammiee5311@gmail.com \
--cc=Vijendar.Mukunda@amd.com \
--cc=broonie@kernel.org \
--cc=daniel.baluta@nxp.com \
--cc=kai.vehmanen@linux.intel.com \
--cc=kapoorarnav43@gmail.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=peter.ujfalusi@linux.intel.com \
--cc=pierre-louis.bossart@linux.dev \
--cc=sound-open-firmware@alsa-project.org \
--cc=tiwai@suse.com \
--cc=yung-chuan.liao@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®