Skip to contentSkip to conversation

ALSA: lola: Bounds check loop iterator against streams array size

PATCH Applied Kees Cook 2 participants 2 messages May 20, 2022 – May 21, 2022 Sound

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 ALSA: lola: Bounds check loop iterator against streams array size

GCC 12 sees that it's technically possible for num_streams to be larger than ARRAY_SIZE(pcm->streams). Bounds-check the iterator.

../sound/pci/lola/lola_pcm.c: In function 'lola_pcm_update':
../sound/pci/lola/lola_pcm.c:567:64: warning: array subscript [0, 31] is outside array bounds of 'struct lola_stream[16]' [-Warray-bounds]
567 | struct lola_stream *str = &pcm->streams[i];
| ~~~~~~~~~~~~^~~
In file included from ../sound/pci/lola/lola_pcm.c:15:
../sound/pci/lola/lola.h:307:28: note: while referencing 'streams'
307 | struct lola_stream streams[MAX_STREAM_COUNT];
| ^~~~~~~

Cc Jaroslav Kysela <[email protected]>
Cc Takashi Iwai <[email protected]>
---
 sound/pci/lola/lola_pcm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
sound/pci/lola/lola_pcm.c +2 -1
index 738ec987000a..32193fae978d 100644
@@ -561,8 +561,9 @@ static snd_pcm_uframes_t lola_pcm_pointer(struct snd_pcm_substream *substream)
 void lola_pcm_update(struct lola *chip, struct lola_pcm *pcm, unsigned int bits)
 {
 	int i;
+	u8 num_streams = min_t(u8, pcm->num_streams, ARRAY_SIZE(pcm->streams));
 
-	for (i = 0; bits && i < pcm->num_streams; i++) {
+	for (i = 0; bits && i < num_streams; i++) {
 		if (bits & (1 << i)) {
 			struct lola_stream *str = &pcm->streams[i];
 			if (str->substream && str->running)
Signature · 1 line
2.32.0
Applied
#1 lore raw
Quoted 13 lines · Kees Cook

GCC 12 sees that it's technically possible for num_streams to be larger than ARRAY_SIZE(pcm->streams). Bounds-check the iterator.

../sound/pci/lola/lola_pcm.c: In function 'lola_pcm_update':
../sound/pci/lola/lola_pcm.c:567:64: warning: array subscript [0, 31] is outside array bounds of 'struct lola_stream[16]' [-Warray-bounds]
567 | struct lola_stream *str = &pcm->streams[i];
| ~~~~~~~~~~~~^~~
In file included from ../sound/pci/lola/lola_pcm.c:15:
../sound/pci/lola/lola.h:307:28: note: while referencing 'streams'
307 | struct lola_stream streams[MAX_STREAM_COUNT];
| ^~~~~~~

Quoted 4 lines
Cc Jaroslav Kysela <[email protected]>
Cc Takashi Iwai <[email protected]>

Thanks, applied now.

Takashi