Skip to content

Commit

Permalink
ASoC: max98090: Move check for invalid values before casting in max98…
Browse files Browse the repository at this point in the history
…090_put_enab_tlv()

[ Upstream commit f7a3444 ]

Validation of signed input should be done before casting to unsigned int.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Suggested-by: Mark Brown <broonie@kernel.org>
Fixes: 2fbe467 ("ASoC: max98090: Reject invalid values in custom control put()")
Link: https://lore.kernel.org/r/1652999486-29653-1-git-send-email-khoroshilov@ispras.ru
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
khoroshilov authored and gregkh committed Jun 9, 2022
1 parent 1b66a53 commit 5348e2e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions sound/soc/codecs/max98090.c
Expand Up @@ -393,7 +393,8 @@ static int max98090_put_enab_tlv(struct snd_kcontrol *kcontrol,
struct soc_mixer_control *mc =
(struct soc_mixer_control *)kcontrol->private_value;
unsigned int mask = (1 << fls(mc->max)) - 1;
unsigned int sel = ucontrol->value.integer.value[0];
int sel_unchecked = ucontrol->value.integer.value[0];
unsigned int sel;
unsigned int val = snd_soc_component_read(component, mc->reg);
unsigned int *select;

Expand All @@ -413,8 +414,9 @@ static int max98090_put_enab_tlv(struct snd_kcontrol *kcontrol,

val = (val >> mc->shift) & mask;

if (sel < 0 || sel > mc->max)
if (sel_unchecked < 0 || sel_unchecked > mc->max)
return -EINVAL;
sel = sel_unchecked;

*select = sel;

Expand Down

0 comments on commit 5348e2e

Please sign in to comment.