Skip to content

Commit 1c5c12e

Browse files
tao-rendavem330
authored andcommitted
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: cb10c7c ("net/ncsi: Add NCSI Broadcom OEM command") Signed-off-by: Tao Ren <[email protected]> Acked-by: Jakub Kicinski <[email protected]> Acked-by: Samuel Mendoza-Jonas <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ffbf987 commit 1c5c12e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

include/linux/etherdevice.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,18 @@ static inline void eth_addr_dec(u8 *addr)
448448
u64_to_ether_addr(u, addr);
449449
}
450450

451+
/**
452+
* eth_addr_inc() - Increment the given MAC address.
453+
* @addr: Pointer to a six-byte array containing Ethernet address to increment.
454+
*/
455+
static inline void eth_addr_inc(u8 *addr)
456+
{
457+
u64 u = ether_addr_to_u64(addr);
458+
459+
u++;
460+
u64_to_ether_addr(u, addr);
461+
}
462+
451463
/**
452464
* is_etherdev_addr - Tell if given Ethernet address belongs to the device.
453465
* @dev: Pointer to a device structure

net/ncsi/ncsi-rsp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/kernel.h>
1212
#include <linux/init.h>
1313
#include <linux/netdevice.h>
14+
#include <linux/etherdevice.h>
1415
#include <linux/skbuff.h>
1516

1617
#include <net/ncsi.h>
@@ -667,7 +668,10 @@ static int ncsi_rsp_handler_oem_bcm_gma(struct ncsi_request *nr)
667668
ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
668669
memcpy(saddr.sa_data, &rsp->data[BCM_MAC_ADDR_OFFSET], ETH_ALEN);
669670
/* Increase mac address by 1 for BMC's address */
670-
saddr.sa_data[ETH_ALEN - 1]++;
671+
eth_addr_inc((u8 *)saddr.sa_data);
672+
if (!is_valid_ether_addr((const u8 *)saddr.sa_data))
673+
return -ENXIO;
674+
671675
ret = ops->ndo_set_mac_address(ndev, &saddr);
672676
if (ret < 0)
673677
netdev_warn(ndev, "NCSI: 'Writing mac address to device failed\n");

0 commit comments

Comments
 (0)