* [PATCH] ALSA: hda: reject invalid values in the IEC958 switch put callbacks
@ 2026-11-23 17:02 Arnav Kapoor
2026-11-24 2:33 ` HyeongJun An
2026-11-24 12:50 ` Takashi Iwai
0 siblings, 2 replies; 3+ messages in thread
From: Arnav Kapoor @ 2026-11-23 17:02 UTC (permalink / raw)
To: Takashi Iwai; +Cc: Jaroslav Kysela, linux-sound, linux-kernel, Arnav Kapoor
snd_hda_spdif_out_switch_put(), snd_hda_spdif_in_switch_put() and
spdif_share_sw_put() treat any non-zero value as "on", so writes of
values outside 0..1, such as 2, -1 or INT_MAX, to these boolean
controls succeed instead of being rejected. snd_hda_mixer_amp_switch_put()
in the same file already returns -EINVAL for them.
Check the value in the same way before taking spdif_mutex.
Signed-off-by: Arnav Kapoor <kapoorarnav43@gmail.com>
---
Tested on a Lenovo V14 G2 ITL (Tiger Lake, SOF, 3 Intel HDMI
converters, 7.0.14-based kernel) with raw SNDRV_CTL_IOCTL_ELEM_WRITE calls
on the three "IEC958 Playback Switch" controls. Stock: 2, -1 and INT_MAX
are all accepted and read back as 1. With this patch applied to the 7.0.14
snd-hda-codec module, all nine invalid writes fail with -EINVAL and leave
the value unchanged, 0 and 1 still work, and the card comes up as before
(no new messages in dmesg).
The SPDIF in and shared switches don't exist on this machine, so those
two hunks are build-tested only (W=1).
sound/hda/common/codec.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/sound/hda/common/codec.c b/sound/hda/common/codec.c
index 51189e305ece..0470f4e085f7 100644
--- a/sound/hda/common/codec.c
+++ b/sound/hda/common/codec.c
@@ -2353,6 +2353,9 @@ static int snd_hda_spdif_out_switch_put(struct snd_kcontrol *kcontrol,
if (WARN_ON(codec->spdif_out.used <= idx))
return -EINVAL;
+ if (ucontrol->value.integer.value[0] < 0 ||
+ ucontrol->value.integer.value[0] > 1)
+ return -EINVAL;
guard(mutex)(&codec->spdif_mutex);
spdif = snd_array_elem(&codec->spdif_out, idx);
nid = spdif->nid;
@@ -2557,9 +2560,11 @@ static int spdif_share_sw_put(struct snd_kcontrol *kcontrol,
{
struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
struct hda_multi_out *mout = (void *)kcontrol->private_value;
- bool val = !!ucontrol->value.integer.value[0];
+ long val = ucontrol->value.integer.value[0];
int change;
+ if (val < 0 || val > 1)
+ return -EINVAL;
guard(mutex)(&codec->spdif_mutex);
change = mout->share_spdif != val;
mout->share_spdif = val;
@@ -2632,9 +2637,11 @@ static int snd_hda_spdif_in_switch_put(struct snd_kcontrol *kcontrol,
{
struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
hda_nid_t nid = kcontrol->private_value;
- unsigned int val = !!ucontrol->value.integer.value[0];
+ long val = ucontrol->value.integer.value[0];
int change;
+ if (val < 0 || val > 1)
+ return -EINVAL;
guard(mutex)(&codec->spdif_mutex);
change = codec->spdif_in_enable != val;
if (change) {
base-commit: 11ef0d515100259c7979f5b4c61b6ea97c6cdc27
--
2.53.0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] ALSA: hda: reject invalid values in the IEC958 switch put callbacks
2026-11-23 17:02 [PATCH] ALSA: hda: reject invalid values in the IEC958 switch put callbacks Arnav Kapoor
@ 2026-11-24 2:33 ` HyeongJun An
2026-11-24 12:50 ` Takashi Iwai
1 sibling, 0 replies; 3+ messages in thread
From: HyeongJun An @ 2026-11-24 2:33 UTC (permalink / raw)
To: Arnav Kapoor
Cc: HyeongJun An, Takashi Iwai, Jaroslav Kysela, linux-sound, linux-kernel
Hello Arnav,
Tested on a Dell Latitude 9420 (Tiger Lake HDMI). On the three IEC958
Playback Switch controls, 2, -1 and INT_MAX now fail with -EINVAL
instead of reading back as 1, and 0 and 1 still work.
Tested-by: HyeongJun An <sammiee5311@gmail.com>
I ran these with Claude Code (Claude Opus 5.5) on the laptop.
Best regards,
HyeongJun An
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ALSA: hda: reject invalid values in the IEC958 switch put callbacks
2026-11-23 17:02 [PATCH] ALSA: hda: reject invalid values in the IEC958 switch put callbacks Arnav Kapoor
2026-11-24 2:33 ` HyeongJun An
@ 2026-11-24 12:50 ` Takashi Iwai
1 sibling, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2026-11-24 12:50 UTC (permalink / raw)
To: Arnav Kapoor; +Cc: Takashi Iwai, Jaroslav Kysela, linux-sound, linux-kernel
On Mon, 23 Nov 2026 18:02:01 +0100,
Arnav Kapoor wrote:
>
> snd_hda_spdif_out_switch_put(), snd_hda_spdif_in_switch_put() and
> spdif_share_sw_put() treat any non-zero value as "on", so writes of
> values outside 0..1, such as 2, -1 or INT_MAX, to these boolean
> controls succeed instead of being rejected. snd_hda_mixer_amp_switch_put()
> in the same file already returns -EINVAL for them.
>
> Check the value in the same way before taking spdif_mutex.
>
> Signed-off-by: Arnav Kapoor <kapoorarnav43@gmail.com>
Applied to for-next branch now. Thanks.
Takashi
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-24 12:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 17:02 [PATCH] ALSA: hda: reject invalid values in the IEC958 switch put callbacks Arnav Kapoor
2026-11-24 2:33 ` HyeongJun An
2026-11-24 12:50 ` Takashi Iwai
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®