[Devel] [PATCH RH9] net: don't skip device_rename for non-root container netns

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Wed Feb 22 15:19:23 MSK 2023


This patch effectively reverts the commit:

2e365f4fbe5d ("ve/net: allow to rename devices in non-ve namespaces")

The patch says that it allows to rename devices, but instead it skips
call to device_rename for non-root netnses of the container. Ending up
with not renamed sysfs link for the renamed device. And if such
inconsistent device with different device name and sysfs name is moved
to root netns of container the systemd-udevd gets an event notification
about it with mixed names. Systemd obviousely does not expect this and
goes mad if at the same time old moved device name intersects with some
other device name in root netns of container, thus systemd disables this
other device (e.g. eth0 and breaks container network).

The original patch from vz6
diff-ve-net-allow-to-rename-devices-in-non-ve-namespaces
seems just to be a crutch for
diff-ve-vedev-dont-call-netdev_fixup_sysfs-if-device_add-was-not-called
so that sysfs entries of vedev don't break on netns creation.

But as we don't have the latter now we also don't need the former.

https://jira.sw.ru/browse/PSBM-145324

Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 include/linux/ve.h |  1 -
 kernel/ve/ve.c     | 15 ---------------
 net/core/dev.c     | 22 ----------------------
 3 files changed, 38 deletions(-)

diff --git a/include/linux/ve.h b/include/linux/ve.h
index a023d9a8d14a..678cd9b6a94a 100644
--- a/include/linux/ve.h
+++ b/include/linux/ve.h
@@ -218,7 +218,6 @@ extern int vz_security_protocol_check(struct net *net, int protocol);
 
 int ve_net_hide_sysctl(struct net *net);
 
-extern struct net *ve_get_net_ns(struct ve_struct* ve);
 extern bool is_ve_init_net(const struct net *net);
 
 #else	/* CONFIG_VE */
diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index 80865161670e..55d45b5f2fbf 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -32,7 +32,6 @@
 #include <linux/ctype.h>
 #include <linux/tty.h>
 #include <linux/device.h>
-#include <net/net_namespace.h>
 
 #include <uapi/linux/vzcalluser.h>
 #include <net/rtnetlink.h>
@@ -283,20 +282,6 @@ int ve_net_hide_sysctl(struct net *net)
 }
 EXPORT_SYMBOL(ve_net_hide_sysctl);
 
-struct net *ve_get_net_ns(struct ve_struct* ve)
-{
-	struct nsproxy *ve_ns;
-	struct net *net_ns;
-
-	rcu_read_lock();
-	ve_ns = rcu_dereference(ve->ve_ns);
-	net_ns = ve_ns ? get_net(ve_ns->net_ns) : NULL;
-	rcu_read_unlock();
-
-	return net_ns;
-}
-EXPORT_SYMBOL(ve_get_net_ns);
-
 bool is_ve_init_net(const struct net *net)
 {
 	struct ve_struct *ve = net->owner_ve;
diff --git a/net/core/dev.c b/net/core/dev.c
index 826584477edb..e901c0b28387 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1135,20 +1135,6 @@ static int dev_get_valid_name(struct net *net, struct net_device *dev,
 	return 0;
 }
 
-#ifdef CONFIG_VE
-static bool ve_dev_can_rename(struct net_device *dev)
-{
-	struct net *net;
-	bool can;
-
-	net = ve_get_net_ns(dev_net(dev)->owner_ve);
-	can = !net || net == dev_net(dev);
-	if (net)
-		put_net(net);
-	return can;
-}
-#endif
-
 /**
  *	dev_change_name - change name of a device
  *	@dev: device
@@ -1208,11 +1194,6 @@ int dev_change_name(struct net_device *dev, const char *newname)
 	dev->name_assign_type = NET_NAME_RENAMED;
 
 rollback:
-#ifdef CONFIG_VE
-	if (!ve_dev_can_rename(dev))
-		goto skip_rename;
-#endif
-
 	ret = device_rename(&dev->dev, dev->name);
 	if (ret) {
 		memcpy(dev->name, oldname, IFNAMSIZ);
@@ -1221,9 +1202,6 @@ int dev_change_name(struct net_device *dev, const char *newname)
 		return ret;
 	}
 
-#ifdef CONFIG_VE
-skip_rename:
-#endif
 	up_write(&devnet_rename_sem);
 
 	netdev_adjacent_rename_links(dev, oldname);
-- 
2.39.2



More information about the Devel mailing list