Patchwork 3c505: do not set pcb->data.raw beyond its size

login
register
mail settings
Submitter roel kluin
Date Feb. 11, 2009, 10:55 p.m.
Message ID <4993576C.8080409@gmail.com>
Download mbox | patch
Permalink /patch/22961/
State Accepted
Delegated to: David Miller
Headers show

Comments

roel kluin - Feb. 11, 2009, 10:55 p.m.
Many thanks, Jarek,

Is this changelog ok?
------------------------------>8----------------8<------------------------------

Ensure that we do not set pcb->data.raw beyond its size, print an error message
and return false if we attempt to. A timout message was printed one too early.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jarek Poplawski - Feb. 12, 2009, 6:37 a.m.
On Wed, Feb 11, 2009 at 11:55:40PM +0100, Roel Kluin wrote:
> Many thanks, Jarek,
> 
> Is this changelog ok?

Yes, the changelog and patch look OK to me.

Thanks,
Jarek P.

> ------------------------------>8----------------8<------------------------------
> 
> Ensure that we do not set pcb->data.raw beyond its size, print an error message
> and return false if we attempt to. A timout message was printed one too early.
> 
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
> diff --git a/drivers/net/3c505.c b/drivers/net/3c505.c
> index 6124605..a8107f9 100644
> --- a/drivers/net/3c505.c
> +++ b/drivers/net/3c505.c
> @@ -493,21 +493,27 @@ static bool receive_pcb(struct net_device *dev, pcb_struct * pcb)
>  	}
>  	/* read the data */
>  	spin_lock_irqsave(&adapter->lock, flags);
> -	i = 0;
> -	do {
> -		j = 0;
> -		while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && j++ < 20000);
> -		pcb->data.raw[i++] = inb_command(dev->base_addr);
> -		if (i > MAX_PCB_DATA)
> -			INVALID_PCB_MSG(i);
> -	} while ((stat & ASF_PCB_MASK) != ASF_PCB_END && j < 20000);
> +	for (i = 0; i < MAX_PCB_DATA; i++) {
> +		for (j = 0; j < 20000; j++) {
> +			stat = get_status(dev->base_addr);
> +			if (stat & ACRF)
> +				break;
> +		}
> +		pcb->data.raw[i] = inb_command(dev->base_addr);
> +		if ((stat & ASF_PCB_MASK) == ASF_PCB_END || j >= 20000)
> +			break;
> +	}
>  	spin_unlock_irqrestore(&adapter->lock, flags);
> +	if (i >= MAX_PCB_DATA) {
> +		INVALID_PCB_MSG(i);
> +		return false;
> +	}
>  	if (j >= 20000) {
>  		TIMEOUT_MSG(__LINE__);
>  		return false;
>  	}
> -	/* woops, the last "data" byte was really the length! */
> -	total_length = pcb->data.raw[--i];
> +	/* the last "data" byte was really the length! */
> +	total_length = pcb->data.raw[i];
>  
>  	/* safety check total length vs data length */
>  	if (total_length != (pcb->length + 2)) {
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller - Feb. 13, 2009, 12:52 a.m.
From: Jarek Poplawski <jarkao2@gmail.com>
Date: Thu, 12 Feb 2009 06:37:15 +0000

> On Wed, Feb 11, 2009 at 11:55:40PM +0100, Roel Kluin wrote:
> > Many thanks, Jarek,
> > 
> > Is this changelog ok?
> 
> Yes, the changelog and patch look OK to me.

Applied, thanks everyone.
--
To unsubscribe from this list: send the line "unsubscribe netdev" 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/net/3c505.c b/drivers/net/3c505.c
index 6124605..a8107f9 100644
--- a/drivers/net/3c505.c
+++ b/drivers/net/3c505.c
@@ -493,21 +493,27 @@  static bool receive_pcb(struct net_device *dev, pcb_struct * pcb)
 	}
 	/* read the data */
 	spin_lock_irqsave(&adapter->lock, flags);
-	i = 0;
-	do {
-		j = 0;
-		while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && j++ < 20000);
-		pcb->data.raw[i++] = inb_command(dev->base_addr);
-		if (i > MAX_PCB_DATA)
-			INVALID_PCB_MSG(i);
-	} while ((stat & ASF_PCB_MASK) != ASF_PCB_END && j < 20000);
+	for (i = 0; i < MAX_PCB_DATA; i++) {
+		for (j = 0; j < 20000; j++) {
+			stat = get_status(dev->base_addr);
+			if (stat & ACRF)
+				break;
+		}
+		pcb->data.raw[i] = inb_command(dev->base_addr);
+		if ((stat & ASF_PCB_MASK) == ASF_PCB_END || j >= 20000)
+			break;
+	}
 	spin_unlock_irqrestore(&adapter->lock, flags);
+	if (i >= MAX_PCB_DATA) {
+		INVALID_PCB_MSG(i);
+		return false;
+	}
 	if (j >= 20000) {
 		TIMEOUT_MSG(__LINE__);
 		return false;
 	}
-	/* woops, the last "data" byte was really the length! */
-	total_length = pcb->data.raw[--i];
+	/* the last "data" byte was really the length! */
+	total_length = pcb->data.raw[i];
 
 	/* safety check total length vs data length */
 	if (total_length != (pcb->length + 2)) {