Skip to contentSkip to conversation

ASoC: max9759: fix underflow in speaker_gain_control_put()

PATCH In review Dan Carpenter 2 participants 2 messages Jan 19, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: max9759: fix underflow in speaker_gain_control_put()

Check for negative values of "priv->gain" to prevent an out of bounds access. The concern is that these might come from the user via:
-> snd_ctl_elem_write_user()

    -> snd_ctl_elem_write()
      -> kctl->put()
Fixes fa8d915172b8 ("ASoC: max9759: Add Amplifier Driver")

---
From static analysis. Not tested.

This patch is obviously harmless but I sometimes get confused about these sound get()/put() functions. I have some code in Smatch which is supposed to manually suppress warnings from snd_ctl_elem_write() but it was four years old and has bitrotted so that's how I got this warning.

So I remember these as being false positives where Smatch gets confused but when I searched my mailbox I just see similar patches which were applied.

 sound/soc/codecs/max9759.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
sound/soc/codecs/max9759.c +2 -1
index d75fd61b9032..bc57d7687f16 100644
@@ -64,7 +64,8 @@ static int speaker_gain_control_put(struct snd_kcontrol *kcontrol,
 	struct snd_soc_component *c = snd_soc_kcontrol_component(kcontrol);
 	struct max9759 *priv = snd_soc_component_get_drvdata(c);
 
-	if (ucontrol->value.integer.value[0] > 3)
+	if (ucontrol->value.integer.value[0] < 0 ||
+	    ucontrol->value.integer.value[0] > 3)
 		return -EINVAL;
 
 	priv->gain = ucontrol->value.integer.value[0];
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 8 lines · Dan Carpenter

Check for negative values of "priv->gain" to prevent an out of bounds access. The concern is that these might come from the user via:
-> snd_ctl_elem_write_user()

    -> snd_ctl_elem_write()
      -> kctl->put()

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-linus

Thanks!

[1/1] ASoC: max9759: fix underflow in speaker_gain_control_put()

      commit: 4c907bcd9dcd233da6707059d777ab389dcbd964

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark