Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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@fb.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Acked-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Tao Ren and committed by
David S. Miller
1c5c12ee ffbf9870

+17 -1
+12
include/linux/etherdevice.h
··· 449 449 } 450 450 451 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 + 463 + /** 452 464 * is_etherdev_addr - Tell if given Ethernet address belongs to the device. 453 465 * @dev: Pointer to a device structure 454 466 * @addr: Pointer to a six-byte array containing the Ethernet address
+5 -1
net/ncsi/ncsi-rsp.c
··· 11 11 #include <linux/kernel.h> 12 12 #include <linux/init.h> 13 13 #include <linux/netdevice.h> 14 + #include <linux/etherdevice.h> 14 15 #include <linux/skbuff.h> 15 16 16 17 #include <net/ncsi.h> ··· 668 667 ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE; 669 668 memcpy(saddr.sa_data, &rsp->data[BCM_MAC_ADDR_OFFSET], ETH_ALEN); 670 669 /* Increase mac address by 1 for BMC's address */ 671 - saddr.sa_data[ETH_ALEN - 1]++; 670 + eth_addr_inc((u8 *)saddr.sa_data); 671 + if (!is_valid_ether_addr((const u8 *)saddr.sa_data)) 672 + return -ENXIO; 673 + 672 674 ret = ops->ndo_set_mac_address(ndev, &saddr); 673 675 if (ret < 0) 674 676 netdev_warn(ndev, "NCSI: 'Writing mac address to device failed\n");