Skip to content

Commit

Permalink
ASoC: ops: Reject out of bounds values in snd_soc_put_volsw()
Browse files Browse the repository at this point in the history
commit 817f7c9 upstream.

We don't currently validate that the values being set are within the range
we advertised to userspace as being valid, do so and reject any values
that are out of range.

Signed-off-by: Mark Brown <broonie@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20220124153253.3548853-2-broonie@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
broonie authored and gregkh committed Feb 8, 2022
1 parent 10007bd commit 9e8895f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions sound/soc/soc-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,27 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
if (sign_bit)
mask = BIT(sign_bit + 1) - 1;

val = ((ucontrol->value.integer.value[0] + min) & mask);
val = ucontrol->value.integer.value[0];
if (mc->platform_max && val > mc->platform_max)
return -EINVAL;
if (val > max - min)
return -EINVAL;
if (val < 0)
return -EINVAL;
val = (val + min) & mask;
if (invert)
val = max - val;
val_mask = mask << shift;
val = val << shift;
if (snd_soc_volsw_is_stereo(mc)) {
val2 = ((ucontrol->value.integer.value[1] + min) & mask);
val2 = ucontrol->value.integer.value[1];
if (mc->platform_max && val2 > mc->platform_max)
return -EINVAL;
if (val2 > max - min)
return -EINVAL;
if (val2 < 0)
return -EINVAL;
val2 = (val2 + min) & mask;
if (invert)
val2 = max - val2;
if (reg == reg2) {
Expand Down

0 comments on commit 9e8895f

Please sign in to comment.