All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] ASoC: Validate written enum values in custom controls
@ 2026-06-09 12:43 HyeongJun An
  2026-06-09 12:43 ` [PATCH 1/4] ASoC: codecs: hdac_hdmi: Validate written enum value HyeongJun An
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: HyeongJun An @ 2026-06-09 12:43 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood
  Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, linux-kernel,
	HyeongJun An

Some custom ASoC kcontrol put() handlers use the written enum value
(ucontrol->value.enumerated.item[0]) to index a table or compute a bit
shift before validating that the value is within the control's enum range.
An out-of-range value written from userspace is therefore consumed before
it is rejected.

This is the same class addressed for the Meson codecs in commit
1e001206804b ("ASoC: meson: g12a-tohdmitx: Validate written enum values")
and commit 3150b70e944e ("ASoC: meson: g12a-toacodec: Validate written
enum values").

Fix four more instances:
 - hdac_hdmi reads e->texts[item] before validation.
 - aiu converts the item before validating it.
 - fsl_audmix converts the item and uses the result before validation.
 - tegra210_ahub reads e->values[item] before validation.

HyeongJun An (4):
  ASoC: codecs: hdac_hdmi: Validate written enum value
  ASoC: meson: aiu: Validate written enum values
  ASoC: fsl: fsl_audmix: Validate written enum values
  ASoC: tegra: tegra210_ahub: Validate written enum value

 sound/soc/codecs/hdac_hdmi.c      | 4 +++-
 sound/soc/fsl/fsl_audmix.c        | 6 ++++++
 sound/soc/meson/aiu-acodec-ctrl.c | 3 +++
 sound/soc/meson/aiu-codec-ctrl.c  | 3 +++
 sound/soc/tegra/tegra210_ahub.c   | 4 +++-
 5 files changed, 18 insertions(+), 2 deletions(-)

-- 
2.43.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] ASoC: codecs: hdac_hdmi: Validate written enum value
  2026-06-09 12:43 [PATCH 0/4] ASoC: Validate written enum values in custom controls HyeongJun An
@ 2026-06-09 12:43 ` HyeongJun An
  2026-06-09 12:43   ` HyeongJun An
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: HyeongJun An @ 2026-06-09 12:43 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood
  Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, linux-kernel,
	HyeongJun An, Jeeja KP, Subhransu S. Prusty, Vinod Koul

hdac_hdmi_set_pin_port_mux() uses the written enum value to index the
texts array before calling snd_soc_dapm_put_enum_double(), which validates
that the value is within the enum item range.

An out-of-range value can therefore make the driver read past the texts
array before the helper rejects the write. Move the lookup after the helper
has accepted the value.

Fixes: 4a3478debf36 ("ASoC: hdac_hdmi: Add jack reporting")
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: HyeongJun An <sammiee5311@gmail.com>
---
 sound/soc/codecs/hdac_hdmi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/hdac_hdmi.c b/sound/soc/codecs/hdac_hdmi.c
index 2652fcf2a3a3..3220f9226e0b 100644
--- a/sound/soc/codecs/hdac_hdmi.c
+++ b/sound/soc/codecs/hdac_hdmi.c
@@ -911,12 +911,14 @@ static int hdac_hdmi_set_pin_port_mux(struct snd_kcontrol *kcontrol,
 	struct hdac_device *hdev = dev_to_hdac_dev(dev);
 	struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
 	struct hdac_hdmi_pcm *pcm;
-	const char *cvt_name =  e->texts[ucontrol->value.enumerated.item[0]];
+	const char *cvt_name;
 
 	ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
 	if (ret < 0)
 		return ret;
 
+	cvt_name = e->texts[ucontrol->value.enumerated.item[0]];
+
 	if (port == NULL)
 		return -EINVAL;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4] ASoC: meson: aiu: Validate written enum values
  2026-06-09 12:43 [PATCH 0/4] ASoC: Validate written enum values in custom controls HyeongJun An
@ 2026-06-09 12:43   ` HyeongJun An
  2026-06-09 12:43   ` HyeongJun An
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: HyeongJun An @ 2026-06-09 12:43 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood
  Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, linux-kernel,
	HyeongJun An, Jerome Brunet, Neil Armstrong, Kevin Hilman,
	Martin Blumenstingl, linux-arm-kernel, linux-amlogic

The AIU HDMI and internal codec mux put callbacks use the written enum
value with snd_soc_enum_item_to_val() before checking whether the value is
valid for the enumeration.

Reject out-of-range values before converting the enum item, matching the
validation already done by the G12A HDMI and internal codec mux controls.

Fixes: b82b734c0e9a ("ASoC: meson: aiu: add hdmi codec control support")
Fixes: 65816025d461 ("ASoC: meson: aiu: add internal dac codec control support")
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: HyeongJun An <sammiee5311@gmail.com>
---
 sound/soc/meson/aiu-acodec-ctrl.c | 3 +++
 sound/soc/meson/aiu-codec-ctrl.c  | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/sound/soc/meson/aiu-acodec-ctrl.c b/sound/soc/meson/aiu-acodec-ctrl.c
index 483772ba69cd..94c5d6533523 100644
--- a/sound/soc/meson/aiu-acodec-ctrl.c
+++ b/sound/soc/meson/aiu-acodec-ctrl.c
@@ -36,6 +36,9 @@ static int aiu_acodec_ctrl_mux_put_enum(struct snd_kcontrol *kcontrol,
 	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
 	unsigned int mux, changed;
 
+	if (ucontrol->value.enumerated.item[0] >= e->items)
+		return -EINVAL;
+
 	mux = snd_soc_enum_item_to_val(e, ucontrol->value.enumerated.item[0]);
 	changed = snd_soc_component_test_bits(component, e->reg,
 					      CTRL_DIN_LRCLK_SRC,
diff --git a/sound/soc/meson/aiu-codec-ctrl.c b/sound/soc/meson/aiu-codec-ctrl.c
index 396f815077e2..60bb4cdfee52 100644
--- a/sound/soc/meson/aiu-codec-ctrl.c
+++ b/sound/soc/meson/aiu-codec-ctrl.c
@@ -28,6 +28,9 @@ static int aiu_codec_ctrl_mux_put_enum(struct snd_kcontrol *kcontrol,
 	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
 	unsigned int mux, changed;
 
+	if (ucontrol->value.enumerated.item[0] >= e->items)
+		return -EINVAL;
+
 	mux = snd_soc_enum_item_to_val(e, ucontrol->value.enumerated.item[0]);
 	changed = snd_soc_component_test_bits(component, e->reg,
 					      CTRL_DATA_SEL,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4] ASoC: meson: aiu: Validate written enum values
@ 2026-06-09 12:43   ` HyeongJun An
  0 siblings, 0 replies; 7+ messages in thread
From: HyeongJun An @ 2026-06-09 12:43 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood
  Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, linux-kernel,
	HyeongJun An, Jerome Brunet, Neil Armstrong, Kevin Hilman,
	Martin Blumenstingl, linux-arm-kernel, linux-amlogic

The AIU HDMI and internal codec mux put callbacks use the written enum
value with snd_soc_enum_item_to_val() before checking whether the value is
valid for the enumeration.

Reject out-of-range values before converting the enum item, matching the
validation already done by the G12A HDMI and internal codec mux controls.

Fixes: b82b734c0e9a ("ASoC: meson: aiu: add hdmi codec control support")
Fixes: 65816025d461 ("ASoC: meson: aiu: add internal dac codec control support")
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: HyeongJun An <sammiee5311@gmail.com>
---
 sound/soc/meson/aiu-acodec-ctrl.c | 3 +++
 sound/soc/meson/aiu-codec-ctrl.c  | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/sound/soc/meson/aiu-acodec-ctrl.c b/sound/soc/meson/aiu-acodec-ctrl.c
index 483772ba69cd..94c5d6533523 100644
--- a/sound/soc/meson/aiu-acodec-ctrl.c
+++ b/sound/soc/meson/aiu-acodec-ctrl.c
@@ -36,6 +36,9 @@ static int aiu_acodec_ctrl_mux_put_enum(struct snd_kcontrol *kcontrol,
 	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
 	unsigned int mux, changed;
 
+	if (ucontrol->value.enumerated.item[0] >= e->items)
+		return -EINVAL;
+
 	mux = snd_soc_enum_item_to_val(e, ucontrol->value.enumerated.item[0]);
 	changed = snd_soc_component_test_bits(component, e->reg,
 					      CTRL_DIN_LRCLK_SRC,
diff --git a/sound/soc/meson/aiu-codec-ctrl.c b/sound/soc/meson/aiu-codec-ctrl.c
index 396f815077e2..60bb4cdfee52 100644
--- a/sound/soc/meson/aiu-codec-ctrl.c
+++ b/sound/soc/meson/aiu-codec-ctrl.c
@@ -28,6 +28,9 @@ static int aiu_codec_ctrl_mux_put_enum(struct snd_kcontrol *kcontrol,
 	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
 	unsigned int mux, changed;
 
+	if (ucontrol->value.enumerated.item[0] >= e->items)
+		return -EINVAL;
+
 	mux = snd_soc_enum_item_to_val(e, ucontrol->value.enumerated.item[0]);
 	changed = snd_soc_component_test_bits(component, e->reg,
 					      CTRL_DATA_SEL,
-- 
2.43.0


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/4] ASoC: fsl: fsl_audmix: Validate written enum values
  2026-06-09 12:43 [PATCH 0/4] ASoC: Validate written enum values in custom controls HyeongJun An
  2026-06-09 12:43 ` [PATCH 1/4] ASoC: codecs: hdac_hdmi: Validate written enum value HyeongJun An
  2026-06-09 12:43   ` HyeongJun An
@ 2026-06-09 12:43 ` HyeongJun An
  2026-06-09 12:43 ` [PATCH 4/4] ASoC: tegra: tegra210_ahub: Validate written enum value HyeongJun An
  3 siblings, 0 replies; 7+ messages in thread
From: HyeongJun An @ 2026-06-09 12:43 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood
  Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, linux-kernel,
	HyeongJun An, Shengjiu Wang, Xiubo Li, Fabio Estevam,
	Nicolin Chen, Viorel Suman, linuxppc-dev

fsl_audmix_put_mix_clk_src() and fsl_audmix_put_out_src()
convert the user-provided enum item with snd_soc_enum_item_to_val()
before checking whether the item is within the enum's item count.

The generic snd_soc_put_enum_double() helper performs that
validation, but these callbacks use the converted value first: the
clock-source path tests it with BIT(), and the output-source path
indexes the prms transition table with it.

Reject out-of-range enum items before converting them.

Fixes: be1df61cf06e ("ASoC: fsl: Add Audio Mixer CPU DAI driver")
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: HyeongJun An <sammiee5311@gmail.com>
---
 sound/soc/fsl/fsl_audmix.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sound/soc/fsl/fsl_audmix.c b/sound/soc/fsl/fsl_audmix.c
index 40a3b7432174..f819f33ec46b 100644
--- a/sound/soc/fsl/fsl_audmix.c
+++ b/sound/soc/fsl/fsl_audmix.c
@@ -117,6 +117,9 @@ static int fsl_audmix_put_mix_clk_src(struct snd_kcontrol *kcontrol,
 	unsigned int *item = ucontrol->value.enumerated.item;
 	unsigned int reg_val, val, mix_clk;
 
+	if (item[0] >= e->items)
+		return -EINVAL;
+
 	/* Get current state */
 	reg_val = snd_soc_component_read(comp, FSL_AUDMIX_CTR);
 	mix_clk = ((reg_val & FSL_AUDMIX_CTR_MIXCLK_MASK)
@@ -157,6 +160,9 @@ static int fsl_audmix_put_out_src(struct snd_kcontrol *kcontrol,
 	unsigned int reg_val, val, mask = 0, ctr = 0;
 	int ret;
 
+	if (item[0] >= e->items)
+		return -EINVAL;
+
 	/* Get current state */
 	reg_val = snd_soc_component_read(comp, FSL_AUDMIX_CTR);
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/4] ASoC: tegra: tegra210_ahub: Validate written enum value
  2026-06-09 12:43 [PATCH 0/4] ASoC: Validate written enum values in custom controls HyeongJun An
                   ` (2 preceding siblings ...)
  2026-06-09 12:43 ` [PATCH 3/4] ASoC: fsl: fsl_audmix: " HyeongJun An
@ 2026-06-09 12:43 ` HyeongJun An
  3 siblings, 0 replies; 7+ messages in thread
From: HyeongJun An @ 2026-06-09 12:43 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood
  Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, linux-kernel,
	HyeongJun An, Thierry Reding, Jonathan Hunter, Sameer Pujar,
	linux-tegra

tegra_ahub_put_value_enum() reads e->values[item[0]] before
checking whether item[0] is within the enum item range. The existing
check therefore happens too late to prevent an out-of-range read of the
values array.

Move the check before the array access.

Fixes: 16e1bcc2caf4 ("ASoC: tegra: Add Tegra210 based AHUB driver")
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: HyeongJun An <sammiee5311@gmail.com>
---
 sound/soc/tegra/tegra210_ahub.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sound/soc/tegra/tegra210_ahub.c b/sound/soc/tegra/tegra210_ahub.c
index ece33b7ff190..efc8f3388668 100644
--- a/sound/soc/tegra/tegra210_ahub.c
+++ b/sound/soc/tegra/tegra210_ahub.c
@@ -62,13 +62,15 @@ static int tegra_ahub_put_value_enum(struct snd_kcontrol *kctl,
 	struct snd_soc_dapm_update update[TEGRA_XBAR_UPDATE_MAX_REG] = { };
 	int val_bytes = snd_soc_component_regmap_val_bytes(cmpnt);
 	unsigned int *item = uctl->value.enumerated.item;
-	unsigned int value = e->values[item[0]];
+	unsigned int value;
 	unsigned int i, bit_pos, reg_idx = 0, reg_val = 0;
 	int change = 0;
 
 	if (item[0] >= e->items)
 		return -EINVAL;
 
+	value = e->values[item[0]];
+
 	if (value) {
 		/* Get the register index and value to set */
 		reg_idx = (value - 1) / (8 * val_bytes);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/4] ASoC: meson: aiu: Validate written enum values
  2026-06-09 12:43   ` HyeongJun An
  (?)
@ 2026-06-09 12:57   ` sashiko-bot
  -1 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-06-09 12:57 UTC (permalink / raw)
  To: HyeongJun An; +Cc: neil.armstrong, linux-amlogic

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing bounds check on user-supplied `item[0]` index leads to an out-of-bounds heap read when evaluating `snd_soc_enum_item_to_val`.
--

commit 9a6f223d3a43c4d946f46b956e844cde37d09bef
Author: HyeongJun An <sammiee5311@gmail.com>

ASoC: meson: aiu: Validate written enum values

This commit fixes missing bounds checking on user-supplied enumeration
values in the AIU HDMI and internal codec mux put callbacks before they
are passed to snd_soc_enum_item_to_val().

> diff --git a/sound/soc/meson/aiu-acodec-ctrl.c b/sound/soc/meson/aiu-acodec-ctrl.c
> index 483772ba69cd7..94c5d65335233 100644
> --- a/sound/soc/meson/aiu-acodec-ctrl.c
> +++ b/sound/soc/meson/aiu-acodec-ctrl.c
> @@ -36,6 +36,9 @@ static int aiu_acodec_ctrl_mux_put_enum(struct snd_kcontrol *kcontrol,
>  	struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
>  	unsigned int mux, changed;
>  
> +	if (ucontrol->value.enumerated.item[0] >= e->items)
> +		return -EINVAL;
> +

[Severity: High]
This is a pre-existing issue, but while you are fixing missing enum
validations here, does sound/soc/sdca/sdca_asoc.c:ge_put_enum_double()
suffer from the exact same out-of-bounds read?

In ge_put_enum_double(), the user-supplied index item[0] is passed to
snd_soc_enum_item_to_val() without verifying if it is less than e->items:

ret = snd_soc_enum_item_to_val(e, item[0]);

Because e->values is dynamically allocated on the heap, an unchecked
large item[0] can read memory past the end of the values buffer. If this
out-of-bounds read hits an unmapped page, could it trigger a page fault
via the ALSA control interface?

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260609124317.38046-1-sammiee5311@gmail.com?part=2

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-06-09 12:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-09 12:43 [PATCH 0/4] ASoC: Validate written enum values in custom controls HyeongJun An
2026-06-09 12:43 ` [PATCH 1/4] ASoC: codecs: hdac_hdmi: Validate written enum value HyeongJun An
2026-06-09 12:43 ` [PATCH 2/4] ASoC: meson: aiu: Validate written enum values HyeongJun An
2026-06-09 12:43   ` HyeongJun An
2026-06-09 12:57   ` sashiko-bot
2026-06-09 12:43 ` [PATCH 3/4] ASoC: fsl: fsl_audmix: " HyeongJun An
2026-06-09 12:43 ` [PATCH 4/4] ASoC: tegra: tegra210_ahub: Validate written enum value HyeongJun An

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.