Skip to contentSkip to conversation

ALSA: Fix for bad ctl access patterns

PATCH In review Takashi Iwai 2 participants 4 messages Apr 7, 2020 Sound

lore
Share & tools
lore
#0 lore raw

cover ALSA: Fix for bad ctl access patterns

Hi,

the recently introduced ctl access validator succeessfully caught some real issues. Here are some fixes.

Takashi

===

Takashi Iwai (2):
ALSA: hda: Fix potential access overflow in beep helper
ALSA: ice1724: Fix invalid access for enumerated ctl items

 sound/pci/hda/hda_beep.c         | 6 +++++-
 sound/pci/ice1712/prodigy_hifi.c | 4 ++--
 2 files changed, 7 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.0
#1 lore raw

PATCH 1/2 ALSA: hda: Fix potential access overflow in beep helper

The beep control helper function blindly stores the values in two stereo channels no matter whether the actual control is mono or stereo. This is practically harmless, but it annoys the recently introduced sanity check, resulting in an error when the checker is enabled.

This patch corrects the behavior to store only on the defined array member.

---
 sound/pci/hda/hda_beep.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
sound/pci/hda/hda_beep.c +5 -1
index f5fd62ed4df5..841523f6b88d 100644
@@ -290,8 +290,12 @@ int snd_hda_mixer_amp_switch_get_beep(struct snd_kcontrol *kcontrol,
 {
 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
 	struct hda_beep *beep = codec->beep;
+	int chs = get_amp_channels(kcontrol);
+
 	if (beep && (!beep->enabled || !ctl_has_mute(kcontrol))) {
-		ucontrol->value.integer.value[0] =
+		if (chs & 1)
+			ucontrol->value.integer.value[0] = beep->enabled;
+		if (chs & 2)
 			ucontrol->value.integer.value[1] = beep->enabled;
 		return 0;
 	}
Signature · 1 line
2.25.0
#2 lore raw

PATCH 2/2 ALSA: ice1724: Fix invalid access for enumerated ctl items

In reply to Takashi Iwai

The access to Analog Capture Source control value implemented in prodigy_hifi.c is wrong, as caught by the recently introduced sanity check; it should be accessing value.enumerated.item[] instead of value.integer.value[]. This patch corrects the wrong access pattern.

---
 sound/pci/ice1712/prodigy_hifi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/pci/ice1712/prodigy_hifi.c +2 -2
index 91f83cef0e56..9aa12a67d370 100644
@@ -536,7 +536,7 @@ static int wm_adc_mux_enum_get(struct snd_kcontrol *kcontrol,
 	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
 
 	mutex_lock(&ice->gpio_mutex);
-	ucontrol->value.integer.value[0] = wm_get(ice, WM_ADC_MUX) & 0x1f;
+	ucontrol->value.enumerated.item[0] = wm_get(ice, WM_ADC_MUX) & 0x1f;
 	mutex_unlock(&ice->gpio_mutex);
 	return 0;
 }
@@ -550,7 +550,7 @@ static int wm_adc_mux_enum_put(struct snd_kcontrol *kcontrol,
 
 	mutex_lock(&ice->gpio_mutex);
 	oval = wm_get(ice, WM_ADC_MUX);
-	nval = (oval & 0xe0) | ucontrol->value.integer.value[0];
+	nval = (oval & 0xe0) | ucontrol->value.enumerated.item[0];
 	if (nval != oval) {
 		wm_put(ice, WM_ADC_MUX, nval);
 		change = 1;
Signature · 1 line
2.25.0
maintainer Reviewed-by on the v1 series
#3 lore raw
In reply to Takashi Iwai

Dne 07. 04. 20 v 10:44 Takashi Iwai napsal(a):

Quoted 4 lines

Hi,

the recently introduced ctl access validator succeessfully caught some real issues. Here are some fixes.

Thanks Takashi for the fixes. For both

Quoted 14 lines

Takashi

===

Takashi Iwai (2):
ALSA: hda: Fix potential access overflow in beep helper
ALSA: ice1724: Fix invalid access for enumerated ctl items

  sound/pci/hda/hda_beep.c         | 6 +++++-
  sound/pci/ice1712/prodigy_hifi.c | 4 ++--
  2 files changed, 7 insertions(+), 3 deletions(-)
Signature · 2 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.