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: <20200814120500.46875-1-dzagorui@cisco.com>
Date:   Fri, 14 Aug 2020 05:05:00 -0700
From:   Denys Zagorui <dzagorui@...co.com>
To:     netdev@...r.kernel.org
Cc:     davem@...emloft.net, kuba@...nel.org, xe-linux-external@...co.com,
        xiyou.wangcong@...il.com, ap420073@...il.com,
        richardcochran@...il.com, f.fainelli@...il.com, andrew@...n.ch,
        mkubecek@...e.cz, linux-kernel@...r.kernel.org
Subject: [RFC][PATCH] net: core: SIOCADDMULTI/SIOCDELMULTI distinguish between uc and mc

SIOCADDMULTI API allows adding multicast/unicast mac addresses but
doesn't deferentiate them so if someone tries to add secondary
unicast mac addr it will be added to multicast netdev list which is
confusing. There is at least one user that allows adding secondary
unicast through this API.
(2f41f3358672 i40e/i40evf: fix unicast mac address add)

This patch adds check whether passed mac addr is uc or mc and adds
this mac addr to the corresponding list. Add 'global' variant for
adding/removing uc addresses similarly to mc.

Signed-off-by: Denys Zagorui <dzagorui@...co.com>
---
 include/linux/netdevice.h    |  2 +
 include/uapi/linux/sockios.h |  2 +-
 net/core/dev_addr_lists.c    | 75 +++++++++++++++++++++++++++---------
 net/core/dev_ioctl.c         | 10 ++++-
 4 files changed, 68 insertions(+), 21 deletions(-)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index b0e303f6603f..9394f369be33 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -4345,8 +4345,10 @@ int dev_addr_init(struct net_device *dev);
 
 /* Functions used for unicast addresses handling */
 int dev_uc_add(struct net_device *dev, const unsigned char *addr);
+int dev_uc_add_global(struct net_device *dev, const unsigned char *addr);
 int dev_uc_add_excl(struct net_device *dev, const unsigned char *addr);
 int dev_uc_del(struct net_device *dev, const unsigned char *addr);
+int dev_uc_del_global(struct net_device *dev, const unsigned char *addr);
 int dev_uc_sync(struct net_device *to, struct net_device *from);
 int dev_uc_sync_multiple(struct net_device *to, struct net_device *from);
 void dev_uc_unsync(struct net_device *to, struct net_device *from);
diff --git a/include/uapi/linux/sockios.h b/include/uapi/linux/sockios.h
index 7d1bccbbef78..f41b152b0268 100644
--- a/include/uapi/linux/sockios.h
+++ b/include/uapi/linux/sockios.h
@@ -80,7 +80,7 @@
 #define SIOCGIFHWADDR	0x8927		/* Get hardware address		*/
 #define SIOCGIFSLAVE	0x8929		/* Driver slaving support	*/
 #define SIOCSIFSLAVE	0x8930
-#define SIOCADDMULTI	0x8931		/* Multicast address lists	*/
+#define SIOCADDMULTI	0x8931		/* Mac address lists	*/
 #define SIOCDELMULTI	0x8932
 #define SIOCGIFINDEX	0x8933		/* name -> if_index mapping	*/
 #define SIOGIFINDEX	SIOCGIFINDEX	/* misprint compatibility :-)	*/
diff --git a/net/core/dev_addr_lists.c b/net/core/dev_addr_lists.c
index 54cd568e7c2f..d150c2d84df4 100644
--- a/net/core/dev_addr_lists.c
+++ b/net/core/dev_addr_lists.c
@@ -573,6 +573,20 @@ int dev_uc_add_excl(struct net_device *dev, const unsigned char *addr)
 }
 EXPORT_SYMBOL(dev_uc_add_excl);
 
+static int __dev_uc_add(struct net_device *dev, const unsigned char *addr,
+			bool global)
+{
+	int err;
+
+	netif_addr_lock_bh(dev);
+	err = __hw_addr_add_ex(&dev->uc, addr, dev->addr_len,
+			       NETDEV_HW_ADDR_T_UNICAST, global, false, 0);
+	if (!err)
+		__dev_set_rx_mode(dev);
+	netif_addr_unlock_bh(dev);
+	return err;
+}
+
 /**
  *	dev_uc_add - Add a secondary unicast address
  *	@dev: device
@@ -583,18 +597,37 @@ EXPORT_SYMBOL(dev_uc_add_excl);
  */
 int dev_uc_add(struct net_device *dev, const unsigned char *addr)
 {
-	int err;
-
-	netif_addr_lock_bh(dev);
-	err = __hw_addr_add(&dev->uc, addr, dev->addr_len,
-			    NETDEV_HW_ADDR_T_UNICAST);
-	if (!err)
-		__dev_set_rx_mode(dev);
-	netif_addr_unlock_bh(dev);
-	return err;
+	return __dev_uc_add(dev, addr, false);
 }
 EXPORT_SYMBOL(dev_uc_add);
 
+/**
+ *	dev_uc_add_global - Add a global unicast address
+ *	@dev: device
+ *	@addr: address to add
+ *
+ *	Add a global unicast address to the device.
+ */
+int dev_uc_add_global(struct net_device *dev, const unsigned char *addr)
+{
+	return __dev_uc_add(dev, addr, true);
+}
+EXPORT_SYMBOL(dev_uc_add_global);
+
+static int __dev_uc_del(struct net_device *dev, const unsigned char *addr,
+			bool global)
+{
+	int err;
+
+	netif_addr_lock_bh(dev);
+	err = __hw_addr_del_ex(&dev->uc, addr, dev->addr_len,
+			       NETDEV_HW_ADDR_T_UNICAST, global, false);
+	if (!err)
+		__dev_set_rx_mode(dev);
+	netif_addr_unlock_bh(dev);
+	return err;
+}
+
 /**
  *	dev_uc_del - Release secondary unicast address.
  *	@dev: device
@@ -605,18 +638,24 @@ EXPORT_SYMBOL(dev_uc_add);
  */
 int dev_uc_del(struct net_device *dev, const unsigned char *addr)
 {
-	int err;
-
-	netif_addr_lock_bh(dev);
-	err = __hw_addr_del(&dev->uc, addr, dev->addr_len,
-			    NETDEV_HW_ADDR_T_UNICAST);
-	if (!err)
-		__dev_set_rx_mode(dev);
-	netif_addr_unlock_bh(dev);
-	return err;
+	return __dev_uc_del(dev, addr, false);
 }
 EXPORT_SYMBOL(dev_uc_del);
 
+/**
+ *	dev_uc_del_global - Delete a global unicast address.
+ *	@dev: device
+ *	@addr: address to delete
+ *
+ *	Release reference to a unicast address and remove it
+ *	from the device if the reference count drops to zero.
+ */
+int dev_uc_del_global(struct net_device *dev, const unsigned char *addr)
+{
+	return __dev_uc_del(dev, addr, true);
+}
+EXPORT_SYMBOL(dev_uc_del_global);
+
 /**
  *	dev_uc_sync - Synchronize device's unicast list to another device
  *	@to: destination device
diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
index b2cf9b7bb7b8..774418f64c05 100644
--- a/net/core/dev_ioctl.c
+++ b/net/core/dev_ioctl.c
@@ -299,7 +299,10 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
 			return -EINVAL;
 		if (!netif_device_present(dev))
 			return -ENODEV;
-		return dev_mc_add_global(dev, ifr->ifr_hwaddr.sa_data);
+		if (is_multicast_ether_addr(ifr->ifr_hwaddr.sa_data))
+			return dev_mc_add_global(dev, ifr->ifr_hwaddr.sa_data);
+		else
+			return dev_uc_add_global(dev, ifr->ifr_hwaddr.sa_data);
 
 	case SIOCDELMULTI:
 		if (!ops->ndo_set_rx_mode ||
@@ -307,7 +310,10 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
 			return -EINVAL;
 		if (!netif_device_present(dev))
 			return -ENODEV;
-		return dev_mc_del_global(dev, ifr->ifr_hwaddr.sa_data);
+		if (is_multicast_ether_addr(ifr->ifr_hwaddr.sa_data))
+			return dev_mc_del_global(dev, ifr->ifr_hwaddr.sa_data);
+		else
+			return dev_uc_del_global(dev, ifr->ifr_hwaddr.sa_data);
 
 	case SIOCSIFTXQLEN:
 		if (ifr->ifr_qlen < 0)
-- 
2.19.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ