Patchwork libata: Read buffer overflow

login
register
mail settings
Submitter roel kluin
Date Aug. 3, 2009, 11:30 a.m.
Message ID <4A76CA64.60802@gmail.com>
Download mbox | patch
Permalink /patch/30499/
State Not Applicable
Delegated to: David Miller
Headers show

Comments

roel kluin - Aug. 3, 2009, 11:30 a.m.
Check whether index is within bounds before grabbing the element.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
James Bottomley - Aug. 3, 2009, 2:37 p.m.
On Mon, 2009-08-03 at 13:30 +0200, Roel Kluin wrote:
> Check whether index is within bounds before grabbing the element.

This isn't a correct description or analysis.

> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
> diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c
> index 2bc2dbe..f88c2ff 100644
> --- a/drivers/ata/pata_mpc52xx.c
> +++ b/drivers/ata/pata_mpc52xx.c
> @@ -294,10 +294,11 @@ mpc52xx_ata_compute_mdma_timings(struct mpc52xx_ata_priv *priv, int dev,
>  				 int speed)
>  {
>  	struct mpc52xx_ata_timings *t = &priv->timings[dev];
> -	const struct mdmaspec *s = &priv->mdmaspec[speed];

This is a *pointer* to the element, *not* a dereference.  It's
irrelevant whether the pointer is off the end of the array or not

> +	const struct mdmaspec *s;
>  
>  	if (speed < 0 || speed > 2)
>  		return -EINVAL;

And since the check is immediately after, the pointer is never
dereferenced.

> +	s = &priv->mdmaspec[speed];

James


--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c
index 2bc2dbe..f88c2ff 100644
--- a/drivers/ata/pata_mpc52xx.c
+++ b/drivers/ata/pata_mpc52xx.c
@@ -294,10 +294,11 @@  mpc52xx_ata_compute_mdma_timings(struct mpc52xx_ata_priv *priv, int dev,
 				 int speed)
 {
 	struct mpc52xx_ata_timings *t = &priv->timings[dev];
-	const struct mdmaspec *s = &priv->mdmaspec[speed];
+	const struct mdmaspec *s;
 
 	if (speed < 0 || speed > 2)
 		return -EINVAL;
+	s = &priv->mdmaspec[speed];
 
 	t->mdma1 = (s->t0M << 24) | (s->td << 16) | (s->tkw << 8) | (s->tm);
 	t->mdma2 = (s->th << 24) | (s->tj << 16) | (s->tn << 8);
@@ -311,10 +312,11 @@  mpc52xx_ata_compute_udma_timings(struct mpc52xx_ata_priv *priv, int dev,
 				 int speed)
 {
 	struct mpc52xx_ata_timings *t = &priv->timings[dev];
-	const struct udmaspec *s = &priv->udmaspec[speed];
+	const struct udmaspec *s;
 
 	if (speed < 0 || speed > 2)
 		return -EINVAL;
+	s = &priv->udmaspec[speed];
 
 	t->udma1 = (s->t2cyc << 24) | (s->tcyc << 16) | (s->tds << 8) | s->tdh;
 	t->udma2 = (s->tdvs << 24) | (s->tdvh << 16) | (s->tfs << 8) | s->tli;