All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: ops: Shift tested values in snd_soc_put_volsw() by +min
@ 2022-02-15 13:06 Marek Vasut
  2022-02-16 18:01 ` Mark Brown
  2022-02-23 14:55 ` Takashi Iwai
  0 siblings, 2 replies; 25+ messages in thread
From: Marek Vasut @ 2022-02-15 13:06 UTC (permalink / raw)
  To: alsa-devel; +Cc: Marek Vasut, Mark Brown, stable

While the $val/$val2 values passed in from userspace are always >= 0
integers, the limits of the control can be signed integers and the $min
can be non-zero and less than zero. To correctly validate $val/$val2
against platform_max, add the $min offset to val first.

Fixes: 817f7c9335ec0 ("ASoC: ops: Reject out of bounds values in snd_soc_put_volsw()")
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Mark Brown <broonie@kernel.org>
Cc: stable@vger.kernel.org
---
 sound/soc/soc-ops.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
index f24f7354f46fe..6389a512c4dc6 100644
--- a/sound/soc/soc-ops.c
+++ b/sound/soc/soc-ops.c
@@ -317,7 +317,7 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
 		mask = BIT(sign_bit + 1) - 1;
 
 	val = ucontrol->value.integer.value[0];
-	if (mc->platform_max && val > mc->platform_max)
+	if (mc->platform_max && ((int)val + min) > mc->platform_max)
 		return -EINVAL;
 	if (val > max - min)
 		return -EINVAL;
@@ -330,7 +330,7 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
 	val = val << shift;
 	if (snd_soc_volsw_is_stereo(mc)) {
 		val2 = ucontrol->value.integer.value[1];
-		if (mc->platform_max && val2 > mc->platform_max)
+		if (mc->platform_max && ((int)val2 + min) > mc->platform_max)
 			return -EINVAL;
 		if (val2 > max - min)
 			return -EINVAL;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2022-05-19 16:00 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-15 13:06 [PATCH] ASoC: ops: Shift tested values in snd_soc_put_volsw() by +min Marek Vasut
2022-02-16 18:01 ` Mark Brown
2022-02-23 14:55 ` Takashi Iwai
2022-02-23 16:32   ` Mark Brown
2022-02-23 16:44     ` Takashi Iwai
2022-02-23 16:52     ` Marek Vasut
2022-02-23 16:52       ` Marek Vasut
2022-05-16 23:53       ` Tan N.
2022-05-16 23:53         ` Tan N.
2022-05-17  1:12         ` [PATCH] ASoC: ops: Fix the bounds checking in snd_soc_put_volsw_sx and snd_soc_put_xr_sx Tan Nayir
2022-05-17  1:12           ` Tan Nayir
2022-05-17 13:04           ` Mark Brown
2022-05-17 13:04             ` Mark Brown
2022-05-17 14:25             ` Tan Nayır
2022-05-17 14:25               ` Tan Nayır
2022-05-17 18:20               ` Mark Brown
2022-05-17 18:20                 ` Mark Brown
2022-05-17 19:58                 ` Tan Nayır
2022-05-17 19:58                   ` Tan Nayır
2022-05-18 12:07                   ` Mark Brown
2022-05-18 12:07                     ` Mark Brown
2022-05-18 23:56                     ` Tan Nayır
2022-05-18 23:56                       ` Tan Nayır
2022-05-19 15:47                       ` Mark Brown
2022-05-19 15:47                         ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.