All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: lola: Bounds check loop iterator against streams array size
@ 2022-05-20 16:55 ` Kees Cook
  0 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2022-05-20 16:55 UTC (permalink / raw)
  To: Jaroslav Kysela
  Cc: Kees Cook, Takashi Iwai, alsa-devel, linux-kernel, linux-hardening

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 <perex@perex.cz>
Cc: Takashi Iwai <tiwai@suse.com>
Cc: alsa-devel@alsa-project.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 sound/pci/lola/lola_pcm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sound/pci/lola/lola_pcm.c b/sound/pci/lola/lola_pcm.c
index 738ec987000a..32193fae978d 100644
--- a/sound/pci/lola/lola_pcm.c
+++ b/sound/pci/lola/lola_pcm.c
@@ -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)
-- 
2.32.0


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

* [PATCH] ALSA: lola: Bounds check loop iterator against streams array size
@ 2022-05-20 16:55 ` Kees Cook
  0 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2022-05-20 16:55 UTC (permalink / raw)
  To: Jaroslav Kysela
  Cc: linux-kernel, alsa-devel, linux-hardening, Kees Cook, Takashi Iwai

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 <perex@perex.cz>
Cc: Takashi Iwai <tiwai@suse.com>
Cc: alsa-devel@alsa-project.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 sound/pci/lola/lola_pcm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sound/pci/lola/lola_pcm.c b/sound/pci/lola/lola_pcm.c
index 738ec987000a..32193fae978d 100644
--- a/sound/pci/lola/lola_pcm.c
+++ b/sound/pci/lola/lola_pcm.c
@@ -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)
-- 
2.32.0


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

* Re: [PATCH] ALSA: lola: Bounds check loop iterator against streams array size
  2022-05-20 16:55 ` Kees Cook
@ 2022-05-21  6:49   ` Takashi Iwai
  -1 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2022-05-21  6:49 UTC (permalink / raw)
  To: Kees Cook
  Cc: Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel, linux-hardening

On Fri, 20 May 2022 18:55:37 +0200,
Kees Cook wrote:
> 
> 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 <perex@perex.cz>
> Cc: Takashi Iwai <tiwai@suse.com>
> Cc: alsa-devel@alsa-project.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Thanks, applied now.


Takashi

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

* Re: [PATCH] ALSA: lola: Bounds check loop iterator against streams array size
@ 2022-05-21  6:49   ` Takashi Iwai
  0 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2022-05-21  6:49 UTC (permalink / raw)
  To: Kees Cook; +Cc: linux-kernel, alsa-devel, linux-hardening, Takashi Iwai

On Fri, 20 May 2022 18:55:37 +0200,
Kees Cook wrote:
> 
> 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 <perex@perex.cz>
> Cc: Takashi Iwai <tiwai@suse.com>
> Cc: alsa-devel@alsa-project.org
> Signed-off-by: Kees Cook <keescook@chromium.org>

Thanks, applied now.


Takashi

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

end of thread, other threads:[~2022-05-21  6:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-20 16:55 [PATCH] ALSA: lola: Bounds check loop iterator against streams array size Kees Cook
2022-05-20 16:55 ` Kees Cook
2022-05-21  6:49 ` Takashi Iwai
2022-05-21  6:49   ` Takashi Iwai

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.