[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <174265449006.356712.8857076514970249603.stgit@pro.pro>
Date: Sat, 22 Mar 2025 17:41:30 +0300
From: Kirill Tkhai <tkhai@...ru>
To: netdev@...r.kernel.org,
linux-kernel@...r.kernel.org
Cc: tkhai@...ru
Subject: [PATCH NET-PREV 29/51] ip6gre: Use __register_netdevice() in .changelink
The objective is to conform .changelink with its 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_gre.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 57cbf7942dc8..e40780da15a0 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -344,6 +344,7 @@ static struct ip6_tnl *ip6gre_tunnel_find(struct net *net,
}
static struct ip6_tnl *ip6gre_tunnel_locate(struct net *net,
+ struct nd_lock *nd_lock,
const struct __ip6_tnl_parm *parms, int create)
{
struct ip6_tnl *t, *nt;
@@ -378,8 +379,11 @@ static struct ip6_tnl *ip6gre_tunnel_locate(struct net *net,
nt->dev = dev;
nt->net = dev_net(dev);
- if (register_netdevice(dev) < 0)
+ attach_nd_lock(dev, nd_lock);
+ if (__register_netdevice(dev) < 0) {
+ detach_nd_lock(dev);
goto failed_free;
+ }
ip6gre_tnl_link_config(nt, 1);
ip6gre_tunnel_link(ign, nt);
@@ -1277,6 +1281,10 @@ static void ip6gre_tnl_parm_to_user(struct ip6_tnl_parm2 *u,
memcpy(u->name, p->name, sizeof(u->name));
}
+/* 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 ip6gre_tunnel_siocdevprivate(struct net_device *dev,
struct ifreq *ifr, void __user *data,
int cmd)
@@ -1287,6 +1295,7 @@ static int ip6gre_tunnel_siocdevprivate(struct net_device *dev,
struct ip6_tnl *t = netdev_priv(dev);
struct net *net = t->net;
struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
+ struct nd_lock *nd_lock;
memset(&p1, 0, sizeof(p1));
@@ -1298,7 +1307,9 @@ static int ip6gre_tunnel_siocdevprivate(struct net_device *dev,
break;
}
ip6gre_tnl_parm_from_user(&p1, &p);
- t = ip6gre_tunnel_locate(net, &p1, 0);
+ lock_netdev(dev, &nd_lock);
+ t = ip6gre_tunnel_locate(net, nd_lock, &p1, 0);
+ unlock_netdev(nd_lock);
if (!t)
t = netdev_priv(dev);
}
@@ -1328,7 +1339,9 @@ static int ip6gre_tunnel_siocdevprivate(struct net_device *dev,
p.o_key = 0;
ip6gre_tnl_parm_from_user(&p1, &p);
- t = ip6gre_tunnel_locate(net, &p1, cmd == SIOCADDTUNNEL);
+ lock_netdev(dev, &nd_lock);
+ t = ip6gre_tunnel_locate(net, nd_lock, &p1, cmd == SIOCADDTUNNEL);
+ unlock_netdev(nd_lock);
if (dev != ign->fb_tunnel_dev && cmd == SIOCCHGTUNNEL) {
if (t) {
@@ -1369,7 +1382,9 @@ static int ip6gre_tunnel_siocdevprivate(struct net_device *dev,
goto done;
err = -ENOENT;
ip6gre_tnl_parm_from_user(&p1, &p);
- t = ip6gre_tunnel_locate(net, &p1, 0);
+ lock_netdev(dev, &nd_lock);
+ t = ip6gre_tunnel_locate(net, nd_lock, &p1, 0);
+ unlock_netdev(nd_lock);
if (!t)
goto done;
err = -EPERM;
@@ -2038,6 +2053,7 @@ ip6gre_changelink_common(struct net_device *dev, struct nlattr *tb[],
struct nlattr *data[], struct __ip6_tnl_parm *p_p,
struct netlink_ext_ack *extack)
{
+ struct nd_lock *nd_lock = rcu_dereference_protected(dev->nd_lock, true);
struct ip6_tnl *t, *nt = netdev_priv(dev);
struct net *net = nt->net;
struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
@@ -2055,7 +2071,7 @@ ip6gre_changelink_common(struct net_device *dev, struct nlattr *tb[],
ip6gre_netlink_parms(data, p_p);
- t = ip6gre_tunnel_locate(net, p_p, 0);
+ t = ip6gre_tunnel_locate(net, nd_lock, p_p, 0);
if (t) {
if (t->dev != dev)
Powered by blists - more mailing lists