2022-06-10 17:47:06

by Daniil Dementev

[permalink] [raw]
Subject: [PATCH] ALSA: usb-audio: US16x08: Move overflow check before array access

Buffer overflow could occur in the loop "while", due to accessing an
array element before checking the index.

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

Signed-off-by: Daniil Dementev <[email protected]>
Reviewed-by: Alexey Khoroshilov <[email protected]>
---
sound/usb/mixer_us16x08.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sound/usb/mixer_us16x08.c b/sound/usb/mixer_us16x08.c
index b7b6f3834ed5..6eb7d93b358d 100644
--- a/sound/usb/mixer_us16x08.c
+++ b/sound/usb/mixer_us16x08.c
@@ -637,10 +637,10 @@ static int snd_get_meter_comp_index(struct snd_us16x08_meter_store *store)
}
} else {
/* skip channels with no compressor active */
- while (!store->comp_store->val[
+ while (store->comp_index <= SND_US16X08_MAX_CHANNELS
+ && !store->comp_store->val[
COMP_STORE_IDX(SND_US16X08_ID_COMP_SWITCH)]
- [store->comp_index - 1]
- && store->comp_index <= SND_US16X08_MAX_CHANNELS) {
+ [store->comp_index - 1]) {
store->comp_index++;
}
ret = store->comp_index++;
--
2.35.1.windows.2


2022-06-13 05:51:46

by Takashi Iwai

[permalink] [raw]
Subject: Re: [PATCH] ALSA: usb-audio: US16x08: Move overflow check before array access

On Fri, 10 Jun 2022 18:57:32 +0200,
Daniil Dementev wrote:
>
> Buffer overflow could occur in the loop "while", due to accessing an
> array element before checking the index.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Signed-off-by: Daniil Dementev <[email protected]>
> Reviewed-by: Alexey Khoroshilov <[email protected]>

Thanks, applied.


Takashi