]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ASoC: tas2562: Validate values for volume writes
authorMark Brown <broonie@kernel.org>
Wed, 15 Jul 2026 20:18:09 +0000 (21:18 +0100)
committerMark Brown <broonie@kernel.org>
Sun, 19 Jul 2026 21:03:22 +0000 (22:03 +0100)
tas2562_volume_control_put() does not do any validation of the control
value written by userspace, it uses it to look up a value in a fixed
size array which can easily be overflowed and then writes whatever value
it gets back to the device.  Add validation that we are loading a value
we have in the array.

Cc: stable@vger.kernel.org
Reviewed-by: Cezary Rojewski <cezary.rojewski@intel.com>
Link: https://patch.msgid.link/20260715-asoc-tas2562-put-retval-v1-1-97bf467c924e@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/tas2562.c

index e1d62f30418ac2b9e08f0547a133edd92cddbf50..40b7803c68bebb20b7b85d381590888c95829c35 100644 (file)
@@ -471,10 +471,14 @@ static int tas2562_volume_control_put(struct snd_kcontrol *kcontrol,
 {
        struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
        struct tas2562_data *tas2562 = snd_soc_component_get_drvdata(component);
-       int ret;
+       int ret, index;
        u32 reg_val;
 
-       reg_val = float_vol_db_lookup[ucontrol->value.integer.value[0]/2];
+       index = ucontrol->value.integer.value[0] / 2;
+       if (index < 0 || index >= ARRAY_SIZE(float_vol_db_lookup))
+               return -EINVAL;
+
+       reg_val = float_vol_db_lookup[index];
        ret = snd_soc_component_write(component, TAS2562_DVC_CFG4,
                                      (reg_val & 0xff));
        if (ret)