[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <174265450440.356712.11114112487526682006.stgit@pro.pro>
Date: Sat, 22 Mar 2025 17:41:44 +0300
From: Kirill Tkhai <tkhai@...ru>
To: netdev@...r.kernel.org,
linux-kernel@...r.kernel.org
Cc: tkhai@...ru
Subject: [PATCH NET-PREV 31/51] ip6_vti: 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_vti.c | 36 ++++++++++++++++++++++++++----------
1 file changed, 26 insertions(+), 10 deletions(-)
diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
index 590737c27537..b20a18c403e9 100644
--- a/net/ipv6/ip6_vti.c
+++ b/net/ipv6/ip6_vti.c
@@ -182,7 +182,7 @@ static int vti6_tnl_create2(struct net_device *dev)
int err;
dev->rtnl_link_ops = &vti6_link_ops;
- err = register_netdevice(dev);
+ err = __register_netdevice(dev);
if (err < 0)
goto out;
@@ -196,7 +196,8 @@ static int vti6_tnl_create2(struct net_device *dev)
return err;
}
-static struct ip6_tnl *vti6_tnl_create(struct net *net, struct __ip6_tnl_parm *p)
+static struct ip6_tnl *vti6_tnl_create(struct net *net, struct nd_lock *nd_lock,
+ struct __ip6_tnl_parm *p)
{
struct net_device *dev;
struct ip6_tnl *t;
@@ -221,6 +222,7 @@ static struct ip6_tnl *vti6_tnl_create(struct net *net, struct __ip6_tnl_parm *p
t->parms = *p;
t->net = dev_net(dev);
+ attach_nd_lock(dev, nd_lock);
err = vti6_tnl_create2(dev);
if (err < 0)
goto failed_free;
@@ -228,6 +230,7 @@ static struct ip6_tnl *vti6_tnl_create(struct net *net, struct __ip6_tnl_parm *p
return t;
failed_free:
+ detach_nd_lock(dev);
free_netdev(dev);
failed:
return NULL;
@@ -247,8 +250,8 @@ static struct ip6_tnl *vti6_tnl_create(struct net *net, struct __ip6_tnl_parm *p
* Return:
* matching tunnel or NULL
**/
-static struct ip6_tnl *vti6_locate(struct net *net, struct __ip6_tnl_parm *p,
- int create)
+static struct ip6_tnl *vti6_locate(struct net *net, struct nd_lock *nd_lock,
+ struct __ip6_tnl_parm *p, int create)
{
const struct in6_addr *remote = &p->raddr;
const struct in6_addr *local = &p->laddr;
@@ -269,7 +272,7 @@ static struct ip6_tnl *vti6_locate(struct net *net, struct __ip6_tnl_parm *p,
}
if (!create)
return NULL;
- return vti6_tnl_create(net, p);
+ return vti6_tnl_create(net, nd_lock, p);
}
/**
@@ -791,6 +794,10 @@ vti6_parm_to_user(struct ip6_tnl_parm2 *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
vti6_siocdevprivate(struct net_device *dev, struct ifreq *ifr, void __user *data, int cmd)
@@ -801,6 +808,7 @@ vti6_siocdevprivate(struct net_device *dev, struct ifreq *ifr, void __user *data
struct ip6_tnl *t = NULL;
struct net *net = dev_net(dev);
struct vti6_net *ip6n = net_generic(net, vti6_net_id);
+ struct nd_lock *nd_lock;
memset(&p1, 0, sizeof(p1));
@@ -812,7 +820,9 @@ vti6_siocdevprivate(struct net_device *dev, struct ifreq *ifr, void __user *data
break;
}
vti6_parm_from_user(&p1, &p);
- t = vti6_locate(net, &p1, 0);
+ lock_netdev(dev, &nd_lock);
+ t = vti6_locate(net, nd_lock, &p1, 0);
+ unlock_netdev(nd_lock);
} else {
memset(&p, 0, sizeof(p));
}
@@ -834,7 +844,9 @@ vti6_siocdevprivate(struct net_device *dev, struct ifreq *ifr, void __user *data
if (p.proto != IPPROTO_IPV6 && p.proto != 0)
break;
vti6_parm_from_user(&p1, &p);
- t = vti6_locate(net, &p1, cmd == SIOCADDTUNNEL);
+ lock_netdev(dev, &nd_lock);
+ t = vti6_locate(net, nd_lock, &p1, cmd == SIOCADDTUNNEL);
+ unlock_netdev(nd_lock);
if (dev != ip6n->fb_tnl_dev && cmd == SIOCCHGTUNNEL) {
if (t) {
if (t->dev != dev) {
@@ -866,7 +878,9 @@ vti6_siocdevprivate(struct net_device *dev, struct ifreq *ifr, void __user *data
break;
err = -ENOENT;
vti6_parm_from_user(&p1, &p);
- t = vti6_locate(net, &p1, 0);
+ lock_netdev(dev, &nd_lock);
+ t = vti6_locate(net, nd_lock, &p1, 0);
+ unlock_netdev(nd_lock);
if (!t)
break;
err = -EPERM;
@@ -1001,6 +1015,7 @@ static int vti6_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 *nt;
@@ -1009,7 +1024,7 @@ static int vti6_newlink(struct net *src_net, struct net_device *dev,
nt->parms.proto = IPPROTO_IPV6;
- if (vti6_locate(net, &nt->parms, 0))
+ if (vti6_locate(net, nd_lock, &nt->parms, 0))
return -EEXIST;
return vti6_tnl_create2(dev);
@@ -1028,6 +1043,7 @@ static int vti6_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;
struct __ip6_tnl_parm p;
struct net *net = dev_net(dev);
@@ -1038,7 +1054,7 @@ static int vti6_changelink(struct net_device *dev, struct nlattr *tb[],
vti6_netlink_parms(data, &p);
- t = vti6_locate(net, &p, 0);
+ t = vti6_locate(net, nd_lock, &p, 0);
if (t) {
if (t->dev != dev)
Powered by blists - more mailing lists