diff mbox series

[v1,net-next,11/11] ipv4: Convert devinet_ioctl to per-netns RTNL.

Message ID 20241018012225.90409-12-kuniyu@amazon.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series ipv4: Convert RTM_{NEW,DEL}ADDR and more to per-netns RTNL. | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5 this patch: 5
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: kory.maincent@bootlin.com
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 38 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 4 this patch: 4
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-10-19--00-00 (tests: 777)

Commit Message

Kuniyuki Iwashima Oct. 18, 2024, 1:22 a.m. UTC
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>
---
 net/core/dev_ioctl.c | 6 +++---
 net/ipv4/devinet.c   | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

Comments

Eric Dumazet Oct. 18, 2024, 1:57 p.m. UTC | #1
On Fri, Oct 18, 2024 at 3:26 AM Kuniyuki Iwashima <kuniyu@amazon.com> wrote:
>
> 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>
kernel test robot Oct. 20, 2024, 3:07 a.m. UTC | #2
Hi Kuniyuki,

kernel test robot noticed the following build warnings:

[auto build test WARNING on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Kuniyuki-Iwashima/rtnetlink-Define-RTNL_FLAG_DOIT_PERNET-for-per-netns-RTNL-doit/20241018-092802
base:   net-next/main
patch link:    https://lore.kernel.org/r/20241018012225.90409-12-kuniyu%40amazon.com
patch subject: [PATCH v1 net-next 11/11] ipv4: Convert devinet_ioctl to per-netns RTNL.
config: x86_64-randconfig-122-20241019 (https://download.01.org/0day-ci/archive/20241020/202410201022.bZkEgzK5-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241020/202410201022.bZkEgzK5-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410201022.bZkEgzK5-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
   net/ipv4/devinet.c:674:47: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *p @@     got struct in_ifaddr [noderef] __rcu * @@
   net/ipv4/devinet.c:674:47: sparse:     expected void *p
   net/ipv4/devinet.c:674:47: sparse:     got struct in_ifaddr [noderef] __rcu *
   net/ipv4/devinet.c:775:65: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *p @@     got struct in_ifaddr [noderef] __rcu * @@
   net/ipv4/devinet.c:775:65: sparse:     expected void *p
   net/ipv4/devinet.c:775:65: sparse:     got struct in_ifaddr [noderef] __rcu *
   net/ipv4/devinet.c:783:73: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *p @@     got struct in_ifaddr [noderef] __rcu * @@
   net/ipv4/devinet.c:783:73: sparse:     expected void *p
   net/ipv4/devinet.c:783:73: sparse:     got struct in_ifaddr [noderef] __rcu *
   net/ipv4/devinet.c:945:9: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *p @@     got struct in_ifaddr [noderef] __rcu *ifa_list @@
   net/ipv4/devinet.c:945:9: sparse:     expected void *p
   net/ipv4/devinet.c:945:9: sparse:     got struct in_ifaddr [noderef] __rcu *ifa_list
   net/ipv4/devinet.c:945:9: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *p @@     got struct in_ifaddr [noderef] __rcu *ifa_next @@
   net/ipv4/devinet.c:945:9: sparse:     expected void *p
   net/ipv4/devinet.c:945:9: sparse:     got struct in_ifaddr [noderef] __rcu *ifa_next
   net/ipv4/devinet.c:1135:63: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *p @@     got struct in_ifaddr [noderef] __rcu * @@
   net/ipv4/devinet.c:1135:63: sparse:     expected void *p
   net/ipv4/devinet.c:1135:63: sparse:     got struct in_ifaddr [noderef] __rcu *
   net/ipv4/devinet.c:1149:63: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *p @@     got struct in_ifaddr [noderef] __rcu * @@
   net/ipv4/devinet.c:1149:63: sparse:     expected void *p
   net/ipv4/devinet.c:1149:63: sparse:     got struct in_ifaddr [noderef] __rcu *
   net/ipv4/devinet.c:1313:9: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *p @@     got struct in_ifaddr [noderef] __rcu *ifa_list @@
   net/ipv4/devinet.c:1313:9: sparse:     expected void *p
   net/ipv4/devinet.c:1313:9: sparse:     got struct in_ifaddr [noderef] __rcu *ifa_list
>> net/ipv4/devinet.c:1313:9: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *p @@     got struct in_ifaddr [noderef] __rcu *const ifa_next @@
   net/ipv4/devinet.c:1313:9: sparse:     expected void *p
   net/ipv4/devinet.c:1313:9: sparse:     got struct in_ifaddr [noderef] __rcu *const ifa_next
   net/ipv4/devinet.c: note: in included file:
   include/linux/inetdevice.h:261:54: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void *p @@     got struct in_device [noderef] __rcu *const ip_ptr @@
   include/linux/inetdevice.h:261:54: sparse:     expected void *p
   include/linux/inetdevice.h:261:54: sparse:     got struct in_device [noderef] __rcu *const ip_ptr
   net/ipv4/devinet.c: note: in included file (through include/linux/inetdevice.h):
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *
   include/linux/rtnetlink.h:153:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   include/linux/rtnetlink.h:153:16: sparse:    void [noderef] __rcu *
   include/linux/rtnetlink.h:153:16: sparse:    void *

vim +1313 net/ipv4/devinet.c

  1299	
  1300	int inet_gifconf(struct net_device *dev, char __user *buf, int len, int size)
  1301	{
  1302		struct in_device *in_dev = __in_dev_get_rtnl_net(dev);
  1303		const struct in_ifaddr *ifa;
  1304		struct ifreq ifr;
  1305		int done = 0;
  1306	
  1307		if (WARN_ON(size > sizeof(struct ifreq)))
  1308			goto out;
  1309	
  1310		if (!in_dev)
  1311			goto out;
  1312	
> 1313		in_dev_for_each_ifa_rtnl_net(dev_net(dev), ifa, in_dev) {
  1314			if (!buf) {
  1315				done += size;
  1316				continue;
  1317			}
  1318			if (len < size)
  1319				break;
  1320			memset(&ifr, 0, sizeof(struct ifreq));
  1321			strcpy(ifr.ifr_name, ifa->ifa_label);
  1322	
  1323			(*(struct sockaddr_in *)&ifr.ifr_addr).sin_family = AF_INET;
  1324			(*(struct sockaddr_in *)&ifr.ifr_addr).sin_addr.s_addr =
  1325									ifa->ifa_local;
  1326	
  1327			if (copy_to_user(buf + done, &ifr, size)) {
  1328				done = -EFAULT;
  1329				break;
  1330			}
  1331			len  -= size;
  1332			done += size;
  1333		}
  1334	out:
  1335		return done;
  1336	}
  1337
diff mbox series

Patch

diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
index 473c437b6b53..46d43b950471 100644
--- a/net/core/dev_ioctl.c
+++ b/net/core/dev_ioctl.c
@@ -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. */
-	rtnl_lock();
+	rtnl_net_lock(net);
 	for_each_netdev(net, dev) {
 		if (!pos)
 			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,
 					    len - total, size);
 		if (done < 0) {
-			rtnl_unlock();
+			rtnl_net_unlock(net);
 			return -EFAULT;
 		}
 		total += done;
 	}
-	rtnl_unlock();
+	rtnl_net_unlock(net);
 
 	return put_user(total, &uifc->ifc_len);
 }
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index f4790859ea69..6089d9255d31 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1299,7 +1299,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)
 {
-	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;
 	struct ifreq ifr;
 	int done = 0;
@@ -1310,7 +1310,7 @@  int inet_gifconf(struct net_device *dev, char __user *buf, int len, int size)
 	if (!in_dev)
 		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) {
 			done += size;
 			continue;