Skip to content

Commit 817f7c9

Browse files
committed
ASoC: ops: Reject out of bounds values in snd_soc_put_volsw()
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 <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 248be35 commit 817f7c9

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

sound/soc/soc-ops.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,27 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
316316
if (sign_bit)
317317
mask = BIT(sign_bit + 1) - 1;
318318

319-
val = ((ucontrol->value.integer.value[0] + min) & mask);
319+
val = ucontrol->value.integer.value[0];
320+
if (mc->platform_max && val > mc->platform_max)
321+
return -EINVAL;
322+
if (val > max - min)
323+
return -EINVAL;
324+
if (val < 0)
325+
return -EINVAL;
326+
val = (val + min) & mask;
320327
if (invert)
321328
val = max - val;
322329
val_mask = mask << shift;
323330
val = val << shift;
324331
if (snd_soc_volsw_is_stereo(mc)) {
325-
val2 = ((ucontrol->value.integer.value[1] + min) & mask);
332+
val2 = ucontrol->value.integer.value[1];
333+
if (mc->platform_max && val2 > mc->platform_max)
334+
return -EINVAL;
335+
if (val2 > max - min)
336+
return -EINVAL;
337+
if (val2 < 0)
338+
return -EINVAL;
339+
val2 = (val2 + min) & mask;
326340
if (invert)
327341
val2 = max - val2;
328342
if (reg == reg2) {

0 commit comments

Comments
 (0)