All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: possible read past array alc88[02]_parse_auto_config()
@ 2009-11-10 19:11 Roel Kluin
  2009-11-11  7:08   ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Roel Kluin @ 2009-11-10 19:11 UTC (permalink / raw)
  To: Jaroslav Kysela, Takashi Iwai, alsa-devel, Andrew Morton, LKML

The test of index `i' is after the read - too late - and
unsafe: if snd_hda_get_connections() fails in the last
iteration a read beyond the array is possible.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
 sound/pci/hda/patch_realtek.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index ff20048..fd094f5 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -4684,9 +4684,9 @@ static int alc880_parse_auto_config(struct hda_codec *codec)
 			spec->multiout.dig_out_nid = dig_nid;
 		else {
 			spec->multiout.slave_dig_outs = spec->slave_dig_outs;
-			spec->slave_dig_outs[i - 1] = dig_nid;
-			if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
+			if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
 				break;
+			spec->slave_dig_outs[i - 1] = dig_nid;
 		}
 	}
 	if (spec->autocfg.dig_in_pin)
@@ -9813,9 +9813,9 @@ static int alc882_parse_auto_config(struct hda_codec *codec)
 			spec->multiout.dig_out_nid = dig_nid;
 		else {
 			spec->multiout.slave_dig_outs = spec->slave_dig_outs;
-			spec->slave_dig_outs[i - 1] = dig_nid;
-			if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
+			if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
 				break;
+			spec->slave_dig_outs[i - 1] = dig_nid;
 		}
 	}
 	if (spec->autocfg.dig_in_pin)

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

* Re: [PATCH] ALSA: possible read past array alc88[02]_parse_auto_config()
  2009-11-10 19:11 [PATCH] ALSA: possible read past array alc88[02]_parse_auto_config() Roel Kluin
@ 2009-11-11  7:08   ` Takashi Iwai
  0 siblings, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2009-11-11  7:08 UTC (permalink / raw)
  To: Roel Kluin; +Cc: Jaroslav Kysela, alsa-devel, Andrew Morton, LKML

At Tue, 10 Nov 2009 20:11:55 +0100,
Roel Kluin wrote:
> 
> The test of index `i' is after the read - too late - and
> unsafe: if snd_hda_get_connections() fails in the last
> iteration a read beyond the array is possible.
> 
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>

Applied now.  Thanks!


Takashi

> ---
>  sound/pci/hda/patch_realtek.c |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
> index ff20048..fd094f5 100644
> --- a/sound/pci/hda/patch_realtek.c
> +++ b/sound/pci/hda/patch_realtek.c
> @@ -4684,9 +4684,9 @@ static int alc880_parse_auto_config(struct hda_codec *codec)
>  			spec->multiout.dig_out_nid = dig_nid;
>  		else {
>  			spec->multiout.slave_dig_outs = spec->slave_dig_outs;
> -			spec->slave_dig_outs[i - 1] = dig_nid;
> -			if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
> +			if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
>  				break;
> +			spec->slave_dig_outs[i - 1] = dig_nid;
>  		}
>  	}
>  	if (spec->autocfg.dig_in_pin)
> @@ -9813,9 +9813,9 @@ static int alc882_parse_auto_config(struct hda_codec *codec)
>  			spec->multiout.dig_out_nid = dig_nid;
>  		else {
>  			spec->multiout.slave_dig_outs = spec->slave_dig_outs;
> -			spec->slave_dig_outs[i - 1] = dig_nid;
> -			if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
> +			if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
>  				break;
> +			spec->slave_dig_outs[i - 1] = dig_nid;
>  		}
>  	}
>  	if (spec->autocfg.dig_in_pin)
> 

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

* Re: [PATCH] ALSA: possible read past array alc88[02]_parse_auto_config()
@ 2009-11-11  7:08   ` Takashi Iwai
  0 siblings, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2009-11-11  7:08 UTC (permalink / raw)
  To: Roel Kluin; +Cc: LKML, alsa-devel, Andrew Morton

At Tue, 10 Nov 2009 20:11:55 +0100,
Roel Kluin wrote:
> 
> The test of index `i' is after the read - too late - and
> unsafe: if snd_hda_get_connections() fails in the last
> iteration a read beyond the array is possible.
> 
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>

Applied now.  Thanks!


Takashi

> ---
>  sound/pci/hda/patch_realtek.c |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
> index ff20048..fd094f5 100644
> --- a/sound/pci/hda/patch_realtek.c
> +++ b/sound/pci/hda/patch_realtek.c
> @@ -4684,9 +4684,9 @@ static int alc880_parse_auto_config(struct hda_codec *codec)
>  			spec->multiout.dig_out_nid = dig_nid;
>  		else {
>  			spec->multiout.slave_dig_outs = spec->slave_dig_outs;
> -			spec->slave_dig_outs[i - 1] = dig_nid;
> -			if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
> +			if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
>  				break;
> +			spec->slave_dig_outs[i - 1] = dig_nid;
>  		}
>  	}
>  	if (spec->autocfg.dig_in_pin)
> @@ -9813,9 +9813,9 @@ static int alc882_parse_auto_config(struct hda_codec *codec)
>  			spec->multiout.dig_out_nid = dig_nid;
>  		else {
>  			spec->multiout.slave_dig_outs = spec->slave_dig_outs;
> -			spec->slave_dig_outs[i - 1] = dig_nid;
> -			if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
> +			if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
>  				break;
> +			spec->slave_dig_outs[i - 1] = dig_nid;
>  		}
>  	}
>  	if (spec->autocfg.dig_in_pin)
> 

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

end of thread, other threads:[~2009-11-11  7:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-10 19:11 [PATCH] ALSA: possible read past array alc88[02]_parse_auto_config() Roel Kluin
2009-11-11  7:08 ` Takashi Iwai
2009-11-11  7:08   ` 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.