aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonas Gorski <jonas.gorski@gmail.com>2012-09-18 08:09:08 -0400
committerRalf Baechle <ralf@linux-mips.org>2012-10-01 05:36:34 -0400
commitd21a7713464c7d35b2cce1fe7f7d87928d6a047e (patch)
tree7ab75a5e3f714ca7ad2eea77cd293bcd1c1d4a8c
parent0b3e06fdc68a06e68687da4eb009ff484bfab449 (diff)
MIPS: BCM63XX: Properly handle mac address octet overflow
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> Cc: linux-mips@linux-mips.org Cc: Maxime Bizon <mbizon@freebox.fr> Cc: Florian Fainelli <florian@openwrt.org> Cc: Sergei Shtylyov <sshtylyov@mvista.com> Patchwork: https://patchwork.linux-mips.org/patch/4348/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
-rw-r--r--arch/mips/bcm63xx/boards/board_bcm963xx.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/arch/mips/bcm63xx/boards/board_bcm963xx.c b/arch/mips/bcm63xx/boards/board_bcm963xx.c
index ea4ea77c6297..442ba96d4004 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)
720 */ 720 */
721static int board_get_mac_address(u8 *mac) 721static int board_get_mac_address(u8 *mac)
722{ 722{
723 u8 *p; 723 u8 *oui;
724 int count; 724 int count;
725 725
726 if (mac_addr_used >= nvram.mac_addr_count) { 726 if (mac_addr_used >= nvram.mac_addr_count) {
@@ -729,21 +729,23 @@ static int board_get_mac_address(u8 *mac)
729 } 729 }
730 730
731 memcpy(mac, nvram.mac_addr_base, ETH_ALEN); 731 memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
732 p = mac + ETH_ALEN - 1; 732 oui = mac + ETH_ALEN/2 - 1;
733 count = mac_addr_used; 733 count = mac_addr_used;
734 734
735 while (count--) { 735 while (count--) {
736 u8 *p = mac + ETH_ALEN - 1;
737
736 do { 738 do {
737 (*p)++; 739 (*p)++;
738 if (*p != 0) 740 if (*p != 0)
739 break; 741 break;
740 p--; 742 p--;
741 } while (p != mac); 743 } while (p != oui);
742 }
743 744
744 if (p == mac) { 745 if (p == oui) {
745 printk(KERN_ERR PFX "unable to fetch mac address\n"); 746 printk(KERN_ERR PFX "unable to fetch mac address\n");
746 return -ENODEV; 747 return -ENODEV;
748 }
747 } 749 }
748 750
749 mac_addr_used++; 751 mac_addr_used++;