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]
Message-ID: <174265449744.356712.714904319843349825.stgit@pro.pro>
Date: Sat, 22 Mar 2025 17:41:37 +0300
From: Kirill Tkhai <tkhai@...ru>
To: netdev@...r.kernel.org,
	linux-kernel@...r.kernel.org
Cc: tkhai@...ru
Subject: [PATCH NET-PREV 30/51] ip6_tunnel: Use __register_netdevice() in .newlink and .changelink

The objective is to conform .newlink and .changelink with their
callers, which already assign nd_lock (and matches master nd_lock
if there is one).

Signed-off-by: Kirill Tkhai <tkhai@...ru>
---
 net/ipv6/ip6_tunnel.c |   37 +++++++++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 10 deletions(-)

diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 87dfb565a9f8..d6435cb1e4fc 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -257,7 +257,7 @@ static int ip6_tnl_create2(struct net_device *dev)
 	int err;
 
 	dev->rtnl_link_ops = &ip6_link_ops;
-	err = register_netdevice(dev);
+	err = __register_netdevice(dev);
 	if (err < 0)
 		goto out;
 
@@ -282,7 +282,8 @@ static int ip6_tnl_create2(struct net_device *dev)
  *   created tunnel or error pointer
  **/
 
-static struct ip6_tnl *ip6_tnl_create(struct net *net, struct __ip6_tnl_parm *p)
+static struct ip6_tnl *ip6_tnl_create(struct net *net, struct nd_lock *nd_lock,
+				      struct __ip6_tnl_parm *p)
 {
 	struct net_device *dev;
 	struct ip6_tnl *t;
@@ -307,6 +308,7 @@ static struct ip6_tnl *ip6_tnl_create(struct net *net, struct __ip6_tnl_parm *p)
 	t = netdev_priv(dev);
 	t->parms = *p;
 	t->net = dev_net(dev);
+	attach_nd_lock(dev, nd_lock);
 	err = ip6_tnl_create2(dev);
 	if (err < 0)
 		goto failed_free;
@@ -314,6 +316,7 @@ static struct ip6_tnl *ip6_tnl_create(struct net *net, struct __ip6_tnl_parm *p)
 	return t;
 
 failed_free:
+	detach_nd_lock(dev);
 	free_netdev(dev);
 failed:
 	return ERR_PTR(err);
@@ -322,6 +325,7 @@ static struct ip6_tnl *ip6_tnl_create(struct net *net, struct __ip6_tnl_parm *p)
 /**
  * ip6_tnl_locate - find or create tunnel matching given parameters
  *   @net: network namespace
+ *   @nd_lock: created device lock
  *   @p: tunnel parameters
  *   @create: != 0 if allowed to create new tunnel if no match found
  *
@@ -335,6 +339,7 @@ static struct ip6_tnl *ip6_tnl_create(struct net *net, struct __ip6_tnl_parm *p)
  **/
 
 static struct ip6_tnl *ip6_tnl_locate(struct net *net,
+		struct nd_lock *nd_lock,
 		struct __ip6_tnl_parm *p, int create)
 {
 	const struct in6_addr *remote = &p->raddr;
@@ -357,7 +362,7 @@ static struct ip6_tnl *ip6_tnl_locate(struct net *net,
 	}
 	if (!create)
 		return ERR_PTR(-ENODEV);
-	return ip6_tnl_create(net, p);
+	return ip6_tnl_create(net, nd_lock, p);
 }
 
 /**
@@ -1621,8 +1626,11 @@ ip6_tnl_parm_to_user(struct ip6_tnl_parm *u, const struct __ip6_tnl_parm *p)
  *   %-EINVAL if passed tunnel parameters are invalid,
  *   %-EEXIST if changing a tunnel's parameters would cause a conflict
  *   %-ENODEV if attempting to change or delete a nonexisting device
- **/
-
+ *
+ * XXX: Currently ->ndo_siocdevprivate is called with @dev unlocked
+ * (the only place where @dev may be locked is phonet_device_autoconf(),
+ *  but it can't be caller of this).
+ */
 static int
 ip6_tnl_siocdevprivate(struct net_device *dev, struct ifreq *ifr,
 		       void __user *data, int cmd)
@@ -1633,6 +1641,7 @@ ip6_tnl_siocdevprivate(struct net_device *dev, struct ifreq *ifr,
 	struct ip6_tnl *t = netdev_priv(dev);
 	struct net *net = t->net;
 	struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
+	struct nd_lock *nd_lock;
 
 	memset(&p1, 0, sizeof(p1));
 
@@ -1644,7 +1653,9 @@ ip6_tnl_siocdevprivate(struct net_device *dev, struct ifreq *ifr,
 				break;
 			}
 			ip6_tnl_parm_from_user(&p1, &p);
-			t = ip6_tnl_locate(net, &p1, 0);
+			lock_netdev(dev, &nd_lock);
+			t = ip6_tnl_locate(net, nd_lock, &p1, 0);
+			unlock_netdev(nd_lock);
 			if (IS_ERR(t))
 				t = netdev_priv(dev);
 		} else {
@@ -1667,7 +1678,9 @@ ip6_tnl_siocdevprivate(struct net_device *dev, struct ifreq *ifr,
 		    p.proto != 0)
 			break;
 		ip6_tnl_parm_from_user(&p1, &p);
-		t = ip6_tnl_locate(net, &p1, cmd == SIOCADDTUNNEL);
+		lock_netdev(dev, &nd_lock);
+		t = ip6_tnl_locate(net, nd_lock, &p1, cmd == SIOCADDTUNNEL);
+		unlock_netdev(nd_lock);
 		if (cmd == SIOCCHGTUNNEL) {
 			if (!IS_ERR(t)) {
 				if (t->dev != dev) {
@@ -1702,7 +1715,9 @@ ip6_tnl_siocdevprivate(struct net_device *dev, struct ifreq *ifr,
 				break;
 			err = -ENOENT;
 			ip6_tnl_parm_from_user(&p1, &p);
-			t = ip6_tnl_locate(net, &p1, 0);
+			lock_netdev(dev, &nd_lock);
+			t = ip6_tnl_locate(net, nd_lock, &p1, 0);
+			unlock_netdev(nd_lock);
 			if (IS_ERR(t))
 				break;
 			err = -EPERM;
@@ -2003,6 +2018,7 @@ static int ip6_tnl_newlink(struct net *src_net, struct net_device *dev,
 			   struct nlattr *tb[], struct nlattr *data[],
 			   struct netlink_ext_ack *extack)
 {
+	struct nd_lock *nd_lock = rcu_dereference_protected(dev->nd_lock, true);
 	struct net *net = dev_net(dev);
 	struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
 	struct ip_tunnel_encap ipencap;
@@ -2023,7 +2039,7 @@ static int ip6_tnl_newlink(struct net *src_net, struct net_device *dev,
 		if (rtnl_dereference(ip6n->collect_md_tun))
 			return -EEXIST;
 	} else {
-		t = ip6_tnl_locate(net, &nt->parms, 0);
+		t = ip6_tnl_locate(net, nd_lock, &nt->parms, 0);
 		if (!IS_ERR(t))
 			return -EEXIST;
 	}
@@ -2039,6 +2055,7 @@ static int ip6_tnl_changelink(struct net_device *dev, struct nlattr *tb[],
 			      struct nlattr *data[],
 			      struct netlink_ext_ack *extack)
 {
+	struct nd_lock *nd_lock = rcu_dereference_protected(dev->nd_lock, true);
 	struct ip6_tnl *t = netdev_priv(dev);
 	struct __ip6_tnl_parm p;
 	struct net *net = t->net;
@@ -2058,7 +2075,7 @@ static int ip6_tnl_changelink(struct net_device *dev, struct nlattr *tb[],
 	if (p.collect_md)
 		return -EINVAL;
 
-	t = ip6_tnl_locate(net, &p, 0);
+	t = ip6_tnl_locate(net, nd_lock, &p, 0);
 	if (!IS_ERR(t)) {
 		if (t->dev != dev)
 			return -EEXIST;


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ