ipv4: Convert devinet_ioctl to per-netns RTNL.

ioctl(SIOCGIFCONF) calls dev_ifconf() that operates on the current netns.

Let's use per-netns RTNL helpers in dev_ifconf() and inet_gifconf().

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
Kuniyuki Iwashima 2024-10-21 11:32:39 -07:00 committed by Paolo Abeni
parent 88d1f87706
commit 7ed8da17bf
2 changed files with 5 additions and 5 deletions

View File

@ -64,7 +64,7 @@ int dev_ifconf(struct net *net, struct ifconf __user *uifc)
} }
/* Loop over the interfaces, and write an info block for each. */ /* Loop over the interfaces, and write an info block for each. */
rtnl_lock(); rtnl_net_lock(net);
for_each_netdev(net, dev) { for_each_netdev(net, dev) {
if (!pos) if (!pos)
done = inet_gifconf(dev, NULL, 0, size); done = inet_gifconf(dev, NULL, 0, size);
@ -72,12 +72,12 @@ int dev_ifconf(struct net *net, struct ifconf __user *uifc)
done = inet_gifconf(dev, pos + total, done = inet_gifconf(dev, pos + total,
len - total, size); len - total, size);
if (done < 0) { if (done < 0) {
rtnl_unlock(); rtnl_net_unlock(net);
return -EFAULT; return -EFAULT;
} }
total += done; total += done;
} }
rtnl_unlock(); rtnl_net_unlock(net);
return put_user(total, &uifc->ifc_len); return put_user(total, &uifc->ifc_len);
} }

View File

@ -1314,7 +1314,7 @@ int devinet_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr)
int inet_gifconf(struct net_device *dev, char __user *buf, int len, int size) int inet_gifconf(struct net_device *dev, char __user *buf, int len, int size)
{ {
struct in_device *in_dev = __in_dev_get_rtnl(dev); struct in_device *in_dev = __in_dev_get_rtnl_net(dev);
const struct in_ifaddr *ifa; const struct in_ifaddr *ifa;
struct ifreq ifr; struct ifreq ifr;
int done = 0; int done = 0;
@ -1325,7 +1325,7 @@ int inet_gifconf(struct net_device *dev, char __user *buf, int len, int size)
if (!in_dev) if (!in_dev)
goto out; goto out;
in_dev_for_each_ifa_rtnl(ifa, in_dev) { in_dev_for_each_ifa_rtnl_net(dev_net(dev), ifa, in_dev) {
if (!buf) { if (!buf) {
done += size; done += size;
continue; continue;