lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20190424012819.2833-1-taoren@fb.com>
Date:   Wed, 24 Apr 2019 01:28:41 +0000
From:   Tao Ren <taoren@...com>
To:     "David S . Miller" <davem@...emloft.net>,
        Maxim Mikityanskiy <maximmi@...lanox.com>,
        Bartosz Golaszewski <bgolaszewski@...libre.com>,
        Samuel Mendoza-Jonas <sam@...dozajonas.com>,
        Jakub Kicinski <jakub.kicinski@...ronome.com>,
        Joel Stanley <joel@....id.au>,
        Andrew Jeffery <andrew@...id.au>,
        "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "openbmc@...ts.ozlabs.org" <openbmc@...ts.ozlabs.org>
CC:     Tao Ren <taoren@...com>
Subject: [PATCH net v3] net/ncsi: handle overflow when incrementing mac
 address

Previously BMC's MAC address is calculated by simply adding 1 to the
last byte of network controller's MAC address, and it produces incorrect
result when network controller's MAC address ends with 0xFF.

The problem can be fixed by calling eth_addr_inc() function to increment
MAC address; besides, the MAC address is also validated before assigning
to BMC.

Fixes: cb10c7c0dfd9 ("net/ncsi: Add NCSI Broadcom OEM command")
Signed-off-by: Tao Ren <taoren@...com>
---
 include/linux/etherdevice.h | 15 +++++++++++++--
 net/ncsi/ncsi-rsp.c         |  6 +++++-
 2 files changed, 18 insertions(+), 3 deletions(-)

Changes in v3:
 - squash changes in "etherdevice.h" into this patch.
 - fix format issue in function comment.
Changes in v2:
 - increment MAC address by calling eth_addr_inc() function.
 - validate MAC address before assigning to BMC.

diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index e2f3b21cd72a..ac5ca754e362 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -436,8 +436,7 @@ static inline void u64_to_ether_addr(u64 u, u8 *addr)
 }
 
 /**
- * eth_addr_dec - Decrement the given MAC address
- *
+ * eth_addr_dec() - Decrement the given MAC address
  * @addr: Pointer to a six-byte array containing Ethernet address to decrement
  */
 static inline void eth_addr_dec(u8 *addr)
@@ -448,6 +447,18 @@ static inline void eth_addr_dec(u8 *addr)
 	u64_to_ether_addr(u, addr);
 }
 
+/**
+ * eth_addr_inc() - Increment the given MAC address.
+ * @addr: Pointer to a six-byte array containing Ethernet address to increment.
+ */
+static inline void eth_addr_inc(u8 *addr)
+{
+	u64 u = ether_addr_to_u64(addr);
+
+	u++;
+	u64_to_ether_addr(u, addr);
+}
+
 /**
  * is_etherdev_addr - Tell if given Ethernet address belongs to the device.
  * @dev: Pointer to a device structure
diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c
index dc07fcc7938e..802db01e3075 100644
--- a/net/ncsi/ncsi-rsp.c
+++ b/net/ncsi/ncsi-rsp.c
@@ -11,6 +11,7 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/netdevice.h>
+#include <linux/etherdevice.h>
 #include <linux/skbuff.h>
 
 #include <net/ncsi.h>
@@ -667,7 +668,10 @@ static int ncsi_rsp_handler_oem_bcm_gma(struct ncsi_request *nr)
 	ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
 	memcpy(saddr.sa_data, &rsp->data[BCM_MAC_ADDR_OFFSET], ETH_ALEN);
 	/* Increase mac address by 1 for BMC's address */
-	saddr.sa_data[ETH_ALEN - 1]++;
+	eth_addr_inc((u8 *)saddr.sa_data);
+	if (!is_valid_ether_addr((const u8 *)saddr.sa_data))
+		return -ENXIO;
+
 	ret = ops->ndo_set_mac_address(ndev, &saddr);
 	if (ret < 0)
 		netdev_warn(ndev, "NCSI: 'Writing mac address to device failed\n");
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ