diff mbox

eexpress: Read buffer overflow

Message ID 4A704C40.1070606@gmail.com
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

roel kluin July 29, 2009, 1:18 p.m. UTC
start_code is 69 words, but the code always writes a multiple of 16 words,
so the last 11 words written are outside the array.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
> Now you seem to make my previous math working :-)
> 
>>> (max) i = 64, (max) j = 14, (64+14+16)/2 = 47 < 69, so it seems to copy
>>> less than its size?
> 
> Jarek P.
> 

You're right, thanks for reviewing, this one should be correct.

--
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

Comments

Jarek Poplawski July 29, 2009, 8:05 p.m. UTC | #1
On Wed, Jul 29, 2009 at 03:18:56PM +0200, Roel Kluin wrote:
> start_code is 69 words, but the code always writes a multiple of 16 words,
> so the last 11 words written are outside the array.
> 
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
> > Now you seem to make my previous math working :-)
> > 
> >>> (max) i = 64, (max) j = 14, (64+14+16)/2 = 47 < 69, so it seems to copy
> >>> less than its size?
> > 
> > Jarek P.
> > 
> 
> You're right, thanks for reviewing, this one should be correct.

Looks OK to me.

Thanks,
Jarek P.

> 
> diff --git a/drivers/net/eexpress.c b/drivers/net/eexpress.c
> index 1686dca..1f016d6 100644
> --- a/drivers/net/eexpress.c
> +++ b/drivers/net/eexpress.c
> @@ -1474,13 +1474,13 @@ static void eexp_hw_init586(struct net_device *dev)
>  	outw(0x0000, ioaddr + 0x800c);
>  	outw(0x0000, ioaddr + 0x800e);
>  
> -	for (i = 0; i < (sizeof(start_code)); i+=32) {
> +	for (i = 0; i < ARRAY_SIZE(start_code) * 2; i+=32) {
>  		int j;
>  		outw(i, ioaddr + SM_PTR);
> -		for (j = 0; j < 16; j+=2)
> +		for (j = 0; j < 16 && (i+j)/2 < ARRAY_SIZE(start_code); j+=2)
>  			outw(start_code[(i+j)/2],
>  			     ioaddr+0x4000+j);
> -		for (j = 0; j < 16; j+=2)
> +		for (j = 0; j < 16 && (i+j+16)/2 < ARRAY_SIZE(start_code); j+=2)
>  			outw(start_code[(i+j+16)/2],
>  			     ioaddr+0x8000+j);
>  	}
--
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 July 30, 2009, 8:28 p.m. UTC | #2
From: Jarek Poplawski <jarkao2@gmail.com>
Date: Wed, 29 Jul 2009 22:05:17 +0200

> On Wed, Jul 29, 2009 at 03:18:56PM +0200, Roel Kluin wrote:
>> start_code is 69 words, but the code always writes a multiple of 16 words,
>> so the last 11 words written are outside the array.
>> 
>> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
>> ---
>> > Now you seem to make my previous math working :-)
>> > 
>> >>> (max) i = 64, (max) j = 14, (64+14+16)/2 = 47 < 69, so it seems to copy
>> >>> less than its size?
>> > 
>> > Jarek P.
>> > 
>> 
>> You're right, thanks for reviewing, this one should be correct.
> 
> Looks OK to me.

Applied.

--
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
diff mbox

Patch

diff --git a/drivers/net/eexpress.c b/drivers/net/eexpress.c
index 1686dca..1f016d6 100644
--- a/drivers/net/eexpress.c
+++ b/drivers/net/eexpress.c
@@ -1474,13 +1474,13 @@  static void eexp_hw_init586(struct net_device *dev)
 	outw(0x0000, ioaddr + 0x800c);
 	outw(0x0000, ioaddr + 0x800e);
 
-	for (i = 0; i < (sizeof(start_code)); i+=32) {
+	for (i = 0; i < ARRAY_SIZE(start_code) * 2; i+=32) {
 		int j;
 		outw(i, ioaddr + SM_PTR);
-		for (j = 0; j < 16; j+=2)
+		for (j = 0; j < 16 && (i+j)/2 < ARRAY_SIZE(start_code); j+=2)
 			outw(start_code[(i+j)/2],
 			     ioaddr+0x4000+j);
-		for (j = 0; j < 16; j+=2)
+		for (j = 0; j < 16 && (i+j+16)/2 < ARRAY_SIZE(start_code); j+=2)
 			outw(start_code[(i+j+16)/2],
 			     ioaddr+0x8000+j);
 	}