linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2 2/2] net/ncsi: handle overflow when incrementing mac address
@ 2019-04-23 21:20 Tao Ren
  0 siblings, 0 replies; 3+ messages in thread
From: Tao Ren @ 2019-04-23 21:20 UTC (permalink / raw)
  To: David S . Miller, Maxim Mikityanskiy, Bartosz Golaszewski,
	netdev, linux-kernel, Jakub Kicinski, Samuel Mendoza-Jonas,
	Joel Stanley, Andrew Jeffery, openbmc
  Cc: Tao Ren

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 "net_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@fb.com>
---
 net/ncsi/ncsi-rsp.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Changes in v2:
 - increment MAC address by calling net_addr_inc function.
 - validate MAC address before assigning to BMC.

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net v2 2/2] net/ncsi: handle overflow when incrementing mac address
@ 2019-04-24  5:30 Tao Ren
  0 siblings, 0 replies; 3+ messages in thread
From: Tao Ren @ 2019-04-24  5:30 UTC (permalink / raw)
  To: David S . Miller, Maxim Mikityanskiy, Bartosz Golaszewski,
	netdev, linux-kernel, Jakub Kicinski, Samuel Mendoza-Jonas,
	Joel Stanley, Andrew Jeffery, openbmc

Please ignore this email. Something was wrong with my email client: the email was supposed to be delivered 8 hours ago but surprisingly it arrived now. Sorry about the noise..

- Tao

On 4/23/19, 9:41 PM, "openbmc on behalf of Tao Ren" <openbmc-bounces+taoren=fb.com@lists.ozlabs.org on behalf of taoren@fb.com> wrote:
> 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 "net_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@fb.com>
 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH net v2 2/2] net/ncsi: handle overflow when incrementing mac address
@ 2019-04-23 22:42 Tao Ren
  0 siblings, 0 replies; 3+ messages in thread
From: Tao Ren @ 2019-04-23 22:42 UTC (permalink / raw)
  To: David S . Miller, Maxim Mikityanskiy, Bartosz Golaszewski,
	netdev, linux-kernel, Jakub Kicinski, Samuel Mendoza-Jonas,
	Joel Stanley, Andrew Jeffery, openbmc
  Cc: Tao Ren

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 "net_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@fb.com>
---
 net/ncsi/ncsi-rsp.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Changes in v2:
 - increment MAC address by calling net_addr_inc function.
 - validate MAC address before assigning to BMC.

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-04-24  5:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-23 21:20 [PATCH net v2 2/2] net/ncsi: handle overflow when incrementing mac address Tao Ren
2019-04-23 22:42 Tao Ren
2019-04-24  5:30 Tao Ren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).