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>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sun, 12 Jul 2020 15:16:23 -0700
From:   Florian Fainelli <f.fainelli@...il.com>
To:     netdev@...r.kernel.org
Cc:     Florian Fainelli <f.fainelli@...il.com>, andrew@...n.ch,
        vivien.didelot@...il.com, mkubecek@...e.cz, kuba@...nel.org,
        davem@...emloft.net
Subject: [PATCH net-next 1/3] net: Introduce netdev_ops_equal

DSA plays some tricks with overloading of a network device's netdev_ops
in order to inject statistics, register dumps or various other
operations. Because the pointer to the netdev_ops is not the same as the
one the network driver registers, checks like theses:

dev->netdev_ops == &foo_ops

will no longer work. In order to allow such tests to continue, introduce
a ndo_equal() function pointer which can be specified by whomever
assignes the net_device::netdev_ops, and in introduce a convenience
function: netdev_ops_equal() which either calls that NDO, or defaults to
a simple pointer comparison.

A subsequent patch will do a tree wide conversion to the helper.

Signed-off-by: Florian Fainelli <f.fainelli@...il.com>
---
 include/linux/netdevice.h | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index ac2cd3f49aba..012033817a35 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1280,6 +1280,9 @@ struct netdev_net_notifier {
  * int (*ndo_tunnel_ctl)(struct net_device *dev, struct ip_tunnel_parm *p,
  *			 int cmd);
  *	Add, change, delete or get information on an IPv4 tunnel.
+ * bool (*ndo_equal)(struct net_device *dev, const struct net_device_ops *ops)
+ *	Returns if the current network device operations are equal to another
+ *	set.
  */
 struct net_device_ops {
 	int			(*ndo_init)(struct net_device *dev);
@@ -1487,6 +1490,8 @@ struct net_device_ops {
 	struct devlink_port *	(*ndo_get_devlink_port)(struct net_device *dev);
 	int			(*ndo_tunnel_ctl)(struct net_device *dev,
 						  struct ip_tunnel_parm *p, int cmd);
+	bool			(*ndo_equal)(struct net_device *dev,
+					     const struct net_device_ops *ops);
 };
 
 /**
@@ -2145,6 +2150,27 @@ struct net_device {
 };
 #define to_net_dev(d) container_of(d, struct net_device, dev)
 
+/**
+ * netdev_ops_equal - Convenience function for testing equality of a
+ * &struct net_device_ops against another.
+ * @dev: &struct net_device instance
+ * @ops: &struct net_device_ops to test against
+ */
+static inline bool netdev_ops_equal(struct net_device *dev,
+				    const struct net_device_ops *ops)
+{
+	if (!dev->netdev_ops->ndo_equal)
+		return dev->netdev_ops == ops;
+
+	return dev->netdev_ops->ndo_equal(dev, ops);
+}
+
+static inline bool __netdev_ops_equal(const struct net_device *dev,
+				      const struct net_device_ops *ops)
+{
+	return netdev_ops_equal((struct net_device *)dev, ops);
+}
+
 static inline bool netif_elide_gro(const struct net_device *dev)
 {
 	if (!(dev->features & NETIF_F_GRO) || dev->xdp_prog)
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ