linux-mips
[Top] [All Lists]

[PATCH] MIPS: BCM63XX: properly handle mac address octet overflow

To: Ralf Baechle <ralf@linux-mips.org>
Subject: [PATCH] MIPS: BCM63XX: properly handle mac address octet overflow
From: Jonas Gorski <jonas.gorski@gmail.com>
Date: Tue, 18 Sep 2012 11:32:08 +0200
Cc: linux-mips@linux-mips.org, Maxime Bizon <mbizon@freebox.fr>, Florian Fainelli <florian@openwrt.org>
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=xOJ01fU+gbK14LkFXPDF1yr2ooHTvaimcs86LIDLOCU=; b=Ft997d4YXubzpMl6mPyLv5Er0idbAqxWuDjVrgRfXP3x3AD/qUDx+Huub0ACug5RwX sjYNOnxBzhqHQhdzg+JzzwT+phnqSZDCbIXTQy+Y8+WTxYQNbfPL7SAPgaFGp5u8SQ58 4Dy1sXPz4r6QXcHD+SbTD+yRO2vYZhl1WmV0u1BmTO9vY2S1tE3qHm8mNGAQ34ReSHC9 mjJ28IMcuQbo7tHnSuGKsmNznhdIAA6c2LSdv9EZkc3RE1cMCjaSCMelEYEO6UOAm5AZ A7XxhVQRPwQJOlprKN7eJWNFYF0WsZeHA7Te93wnl0XX/rnh5HY6edKCFlDWl2j8ZN9L KUNg==
List-archive: <http://www.linux-mips.org/archives/linux-mips/>
List-help: <mailto:ecartis@linux-mips.org?Subject=help>
List-id: linux-mips <linux-mips.eddie.linux-mips.org>
List-owner: <mailto:ralf@linux-mips.org>
List-post: <mailto:linux-mips@linux-mips.org>
List-software: Ecartis version 1.0.0
List-subscribe: <mailto:ecartis@linux-mips.org?subject=subscribe%20linux-mips>
List-unsubscribe: <mailto:ecartis@linux-mips.org?subject=unsubscribe%20linux-mips>
Sender: linux-mips-bounce@linux-mips.org
While calculating the mac address the pointer for the current octet was
never reset back to the least significant one after being decremented
because of an octet overflow. This resulted in the code continuing to
increment at the current octet, potentially generating duplicate or
invalid mac addresses.

As a second issue the pointer was allowed to advance up to the most
significant octet, modifying the OUI, and potentially changing the type
of mac address.

Rewrite the code so it resets the pointer to the least significant
in each outer loop step, and bails out when the least significant octet
of the OUI is reached.

Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
---
 arch/mips/bcm63xx/boards/board_bcm963xx.c |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/arch/mips/bcm63xx/boards/board_bcm963xx.c 
b/arch/mips/bcm63xx/boards/board_bcm963xx.c
index ea4ea77..f0fcec6 100644
--- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
+++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
@@ -720,7 +720,7 @@ const char *board_get_name(void)
  */
 static int board_get_mac_address(u8 *mac)
 {
-       u8 *p;
+       u8 *oui;
        int count;
 
        if (mac_addr_used >= nvram.mac_addr_count) {
@@ -729,21 +729,23 @@ static int board_get_mac_address(u8 *mac)
        }
 
        memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
-       p = mac + ETH_ALEN - 1;
+       oui = mac + ETH_ALEN/2 - 1;
        count = mac_addr_used;
 
        while (count--) {
+               p = mac + ETH_ALEN - 1;
+
                do {
                        (*p)++;
                        if (*p != 0)
                                break;
                        p--;
-               } while (p != mac);
-       }
+               } while (p != oui);
 
-       if (p == mac) {
-               printk(KERN_ERR PFX "unable to fetch mac address\n");
-               return -ENODEV;
+               if (p == oui) {
+                       printk(KERN_ERR PFX "unable to fetch mac address\n");
+                       return -ENODEV;
+               }
        }
 
        mac_addr_used++;
-- 
1.7.10.4


<Prev in Thread] Current Thread [Next in Thread>