Subject: Re: [PATCH] [IPV4]: Buffer overflow

From: Roel Kluin <[email-masked]>
Date: Thu, 30 Jul 2009 11:46:59 +0200

If arp_format_neigh_entry() can be called with n->dev->addr_len == 0, then a
write to hbuffer[-1] occurs.

Signed-off-by: Roel Kluin <[email-masked]>
---
Op 30-07-09 00:02, Jarek Poplawski schreef:
> Roel Kluin wrote, On 07/29/2009 12:52 PM:

>> -	hbuffer[--k] = 0;
>> +	if (k != 0)
>> +		hbuffer[--k] = 0;
> 
> 
> I guess for k == 0 we need hbuffer[0] = 0 too.
> 
> Jarek P.

Thanks, updated patch below.

diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c
index c29d75d..090e999 100644
--- a/net/ipv4/arp.c
+++ b/net/ipv4/arp.c
@@ -1304,7 +1304,9 @@ static void arp_format_neigh_entry(struct seq_file *seq,
 		hbuffer[k++] = hex_asc_lo(n->ha[j]);
 		hbuffer[k++] = ':';
 	}
-	hbuffer[--k] = 0;
+	if (k != 0)
+		--k;
+	hbuffer[k] = 0;
 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
 	}
 #endif