All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v4] net/ncsi: handle overflow when incrementing mac address
@ 2019-04-24  1:43 Tao Ren
  2019-04-24  1:44   ` Jakub Kicinski
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Tao Ren @ 2019-04-24  1:43 UTC (permalink / raw)
  To: David S . Miller, Maxim Mikityanskiy, Bartosz Golaszewski,
	Samuel Mendoza-Jonas, Jakub Kicinski, Joel Stanley,
	Andrew Jeffery, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org
  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 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>
---
 include/linux/etherdevice.h | 12 ++++++++++++
 net/ncsi/ncsi-rsp.c         |  6 +++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

Changes in v4:
 - revert the changes in eth_addr_dec() function comment.
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..aa8bfd6f738c 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -448,6 +448,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


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

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

On Wed, 24 Apr 2019 01:43:32 +0000, Tao Ren 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 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>

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

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

On Wed, 24 Apr 2019 01:43:32 +0000, Tao Ren 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 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>

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

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

On Wed, 2019-04-24 at 01:43 +0000, Tao Ren 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 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: Samuel Mendoza-Jonas <sam@mendozajonas.com>

> ---
>  include/linux/etherdevice.h | 12 ++++++++++++
>  net/ncsi/ncsi-rsp.c         |  6 +++++-
>  2 files changed, 17 insertions(+), 1 deletion(-)
> 
> Changes in v4:
>  - revert the changes in eth_addr_dec() function comment.
> 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..aa8bfd6f738c 100644
> --- a/include/linux/etherdevice.h
> +++ b/include/linux/etherdevice.h
> @@ -448,6 +448,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
> 

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

* Re: [PATCH net v4] net/ncsi: handle overflow when incrementing mac address
  2019-04-24  1:43 [PATCH net v4] net/ncsi: handle overflow when incrementing mac address Tao Ren
  2019-04-24  1:44   ` Jakub Kicinski
  2019-04-24  3:49 ` Samuel Mendoza-Jonas
@ 2019-04-24  4:16 ` David Miller
  2 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2019-04-24  4:16 UTC (permalink / raw)
  To: taoren
  Cc: maximmi, bgolaszewski, sam, jakub.kicinski, joel, andrew, netdev,
	linux-kernel, openbmc

From: Tao Ren <taoren@fb.com>
Date: Wed, 24 Apr 2019 01:43:32 +0000

> 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>

Applied and queued up for -stable, thanks everyone.

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

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

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-24  1:43 [PATCH net v4] net/ncsi: handle overflow when incrementing mac address Tao Ren
2019-04-24  1:44 ` Jakub Kicinski
2019-04-24  1:44   ` Jakub Kicinski
2019-04-24  3:49 ` Samuel Mendoza-Jonas
2019-04-24  4:16 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.