From: Tan Nayir <tannayir@gmail.com>
To: alsa-devel@alsa-project.org
Cc: Marek Vasut <marex@denx.de>, Tan Nayir <tannayir@gmail.com>,
Mark Brown <broonie@kernel.org>,
stable@vger.kernel.org
Subject: [PATCH] ASoC: ops: Fix the bounds checking in snd_soc_put_volsw_sx and snd_soc_put_xr_sx
Date: Tue, 17 May 2022 04:12:04 +0300 [thread overview]
Message-ID: <20220517011201.23530-1-tannayir@gmail.com> (raw)
In-Reply-To: <c2163c71-2f71-9011-3966-baeab8e8dc8f@gmail.com>
The $val in both functions has a range between 0 and an arbitrary limit
whereas the range specified with the $min and $max can start
from a negative number. To do the out of bound check correctly, the
$val must be added the $min offset.
Previous-discussion: https://lore.kernel.org/all/c2163c71-2f71-9011-3966-baeab8e8dc8f@gmail.com/
Fixes: 4f1e50d6a9cf9 ("ASoC: ops: Reject out of bounds values in snd_soc_put_volsw_sx()")
Fixes: 4cf28e9ae6e2e ("ASoC: ops: Reject out of bounds values in snd_soc_put_xr_sx()")
Signed-off-by: Tan Nayir <tannayir@gmail.com>
---
sound/soc/soc-ops.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
index e693070f5..42191968c 100644
--- a/sound/soc/soc-ops.c
+++ b/sound/soc/soc-ops.c
@@ -433,7 +433,7 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
if (ucontrol->value.integer.value[0] < 0)
return -EINVAL;
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;
@@ -910,11 +910,12 @@ int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
unsigned int invert = mc->invert;
unsigned long mask = (1UL<<mc->nbits)-1;
long max = mc->max;
+ long min = mc->min;
long val = ucontrol->value.integer.value[0];
int ret = 0;
unsigned int i;
- if (val < mc->min || val > mc->max)
+ if (val < mc->min || ((int)val + min) > mc->max)
return -EINVAL;
if (invert)
val = max - val;
--
2.25.1
next prev parent reply other threads:[~2022-05-17 13:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
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-05-16 23:53 ` Tan N.
2022-05-17 1:12 ` Tan Nayir [this message]
2022-05-17 13:04 ` [PATCH] ASoC: ops: Fix the bounds checking in snd_soc_put_volsw_sx and snd_soc_put_xr_sx Mark Brown
2022-05-17 14:25 ` Tan Nayır
2022-05-17 18:20 ` Mark Brown
2022-05-17 19:58 ` Tan Nayır
2022-05-18 12:07 ` Mark Brown
2022-05-18 23:56 ` Tan Nayır
2022-05-19 15:47 ` Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220517011201.23530-1-tannayir@gmail.com \
--to=tannayir@gmail.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=marex@denx.de \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).