netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: fix removing a namespace with conflicting altnames
@ 2024-01-19  0:58 Jakub Kicinski
  2024-01-19 13:23 ` Eric Dumazet
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Jakub Kicinski @ 2024-01-19  0:58 UTC (permalink / raw)
  To: davem
  Cc: netdev, edumazet, pabeni, Jakub Kicinski,
	Марк Коренберг,
	daniel, jiri, lucien.xin, johannes.berg

Mark reports a BUG() when a net namespace is removed.

    kernel BUG at net/core/dev.c:11520!

Physical interfaces moved outside of init_net get "refunded"
to init_net when that namespace disappears. The main interface
name may get overwritten in the process if it would have
conflicted. We need to also discard all conflicting altnames.
Recent fixes addressed ensuring that altnames get moved
with the main interface, which surfaced this problem.

Reported-by: Марк Коренберг <socketpair@gmail.com>
Link: https://lore.kernel.org/all/CAEmTpZFZ4Sv3KwqFOY2WKDHeZYdi0O7N5H1nTvcGp=SAEavtDg@mail.gmail.com/
Fixes: 7663d522099e ("net: check for altname conflicts when changing netdev's netns")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: daniel@iogearbox.net
CC: jiri@resnulli.us
CC: lucien.xin@gmail.com
CC: johannes.berg@intel.com

I'll follow up with a conversion to RCU freeing in -next.
---
 net/core/dev.c | 9 +++++++++
 net/core/dev.h | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/net/core/dev.c b/net/core/dev.c
index f01a9b858347..cb2dab0feee0 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -11551,6 +11551,7 @@ static struct pernet_operations __net_initdata netdev_net_ops = {
 
 static void __net_exit default_device_exit_net(struct net *net)
 {
+	struct netdev_name_node *name_node, *tmp;
 	struct net_device *dev, *aux;
 	/*
 	 * Push all migratable network devices back to the
@@ -11573,6 +11574,14 @@ static void __net_exit default_device_exit_net(struct net *net)
 		snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex);
 		if (netdev_name_in_use(&init_net, fb_name))
 			snprintf(fb_name, IFNAMSIZ, "dev%%d");
+
+		netdev_for_each_altname_safe(dev, name_node, tmp)
+			if (netdev_name_in_use(&init_net, name_node->name)) {
+				netdev_name_node_del(name_node);
+				synchronize_rcu();
+				__netdev_name_node_alt_destroy(name_node);
+			}
+
 		err = dev_change_net_namespace(dev, &init_net, fb_name);
 		if (err) {
 			pr_emerg("%s: failed to move %s to init_net: %d\n",
diff --git a/net/core/dev.h b/net/core/dev.h
index cf93e188785b..7480b4c84298 100644
--- a/net/core/dev.h
+++ b/net/core/dev.h
@@ -63,6 +63,9 @@ int dev_change_name(struct net_device *dev, const char *newname);
 
 #define netdev_for_each_altname(dev, namenode)				\
 	list_for_each_entry((namenode), &(dev)->name_node->list, list)
+#define netdev_for_each_altname_safe(dev, namenode, next)		\
+	list_for_each_entry_safe((namenode), (next), &(dev)->name_node->list, \
+				 list)
 
 int netdev_name_node_alt_create(struct net_device *dev, const char *name);
 int netdev_name_node_alt_destroy(struct net_device *dev, const char *name);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net: fix removing a namespace with conflicting altnames
  2024-01-19  0:58 [PATCH net] net: fix removing a namespace with conflicting altnames Jakub Kicinski
@ 2024-01-19 13:23 ` Eric Dumazet
  2024-01-19 15:15 ` Jiri Pirko
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Dumazet @ 2024-01-19 13:23 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, netdev, pabeni,
	Марк Коренберг,
	daniel, jiri, lucien.xin, johannes.berg

On Fri, Jan 19, 2024 at 1:59 AM Jakub Kicinski <kuba@kernel.org> wrote:
>
> Mark reports a BUG() when a net namespace is removed.
>
>     kernel BUG at net/core/dev.c:11520!
>
> Physical interfaces moved outside of init_net get "refunded"
> to init_net when that namespace disappears. The main interface
> name may get overwritten in the process if it would have
> conflicted. We need to also discard all conflicting altnames.
> Recent fixes addressed ensuring that altnames get moved
> with the main interface, which surfaced this problem.
>
> Reported-by: Марк Коренберг <socketpair@gmail.com>
> Link: https://lore.kernel.org/all/CAEmTpZFZ4Sv3KwqFOY2WKDHeZYdi0O7N5H1nTvcGp=SAEavtDg@mail.gmail.com/
> Fixes: 7663d522099e ("net: check for altname conflicts when changing netdev's netns")
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> CC: daniel@iogearbox.net
> CC: jiri@resnulli.us
> CC: lucien.xin@gmail.com
> CC: johannes.berg@intel.com
>
> I'll follow up with a conversion to RCU freeing in -next.

Okay then...

Reviewed-by: Eric Dumazet <edumazet@google.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net: fix removing a namespace with conflicting altnames
  2024-01-19  0:58 [PATCH net] net: fix removing a namespace with conflicting altnames Jakub Kicinski
  2024-01-19 13:23 ` Eric Dumazet
@ 2024-01-19 15:15 ` Jiri Pirko
  2024-01-19 16:18 ` Xin Long
  2024-01-22  1:34 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Jiri Pirko @ 2024-01-19 15:15 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, netdev, edumazet, pabeni,
	Марк Коренберг,
	daniel, lucien.xin, johannes.berg

Fri, Jan 19, 2024 at 01:58:59AM CET, kuba@kernel.org wrote:
>Mark reports a BUG() when a net namespace is removed.
>
>    kernel BUG at net/core/dev.c:11520!
>
>Physical interfaces moved outside of init_net get "refunded"
>to init_net when that namespace disappears. The main interface
>name may get overwritten in the process if it would have
>conflicted. We need to also discard all conflicting altnames.
>Recent fixes addressed ensuring that altnames get moved
>with the main interface, which surfaced this problem.
>
>Reported-by: Марк Коренберг <socketpair@gmail.com>
>Link: https://lore.kernel.org/all/CAEmTpZFZ4Sv3KwqFOY2WKDHeZYdi0O7N5H1nTvcGp=SAEavtDg@mail.gmail.com/
>Fixes: 7663d522099e ("net: check for altname conflicts when changing netdev's netns")
>Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Reviewed-by: Jiri Pirko <jiri@nvidia.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net: fix removing a namespace with conflicting altnames
  2024-01-19  0:58 [PATCH net] net: fix removing a namespace with conflicting altnames Jakub Kicinski
  2024-01-19 13:23 ` Eric Dumazet
  2024-01-19 15:15 ` Jiri Pirko
@ 2024-01-19 16:18 ` Xin Long
  2024-01-22  1:34 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Xin Long @ 2024-01-19 16:18 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, netdev, edumazet, pabeni,
	Марк Коренберг,
	daniel, jiri, johannes.berg

On Thu, Jan 18, 2024 at 7:59 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> Mark reports a BUG() when a net namespace is removed.
>
>     kernel BUG at net/core/dev.c:11520!
>
> Physical interfaces moved outside of init_net get "refunded"
> to init_net when that namespace disappears. The main interface
> name may get overwritten in the process if it would have
> conflicted. We need to also discard all conflicting altnames.
> Recent fixes addressed ensuring that altnames get moved
> with the main interface, which surfaced this problem.
>
> Reported-by: Марк Коренберг <socketpair@gmail.com>
> Link: https://lore.kernel.org/all/CAEmTpZFZ4Sv3KwqFOY2WKDHeZYdi0O7N5H1nTvcGp=SAEavtDg@mail.gmail.com/
> Fixes: 7663d522099e ("net: check for altname conflicts when changing netdev's netns")
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Reviewed-by: Xin Long <lucien.xin@gmail.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] net: fix removing a namespace with conflicting altnames
  2024-01-19  0:58 [PATCH net] net: fix removing a namespace with conflicting altnames Jakub Kicinski
                   ` (2 preceding siblings ...)
  2024-01-19 16:18 ` Xin Long
@ 2024-01-22  1:34 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-01-22  1:34 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, netdev, edumazet, pabeni, socketpair, daniel, jiri,
	lucien.xin, johannes.berg

Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:

On Thu, 18 Jan 2024 16:58:59 -0800 you wrote:
> Mark reports a BUG() when a net namespace is removed.
> 
>     kernel BUG at net/core/dev.c:11520!
> 
> Physical interfaces moved outside of init_net get "refunded"
> to init_net when that namespace disappears. The main interface
> name may get overwritten in the process if it would have
> conflicted. We need to also discard all conflicting altnames.
> Recent fixes addressed ensuring that altnames get moved
> with the main interface, which surfaced this problem.
> 
> [...]

Here is the summary with links:
  - [net] net: fix removing a namespace with conflicting altnames
    https://git.kernel.org/netdev/net/c/d09486a04f5d

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-22  1:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-19  0:58 [PATCH net] net: fix removing a namespace with conflicting altnames Jakub Kicinski
2024-01-19 13:23 ` Eric Dumazet
2024-01-19 15:15 ` Jiri Pirko
2024-01-19 16:18 ` Xin Long
2024-01-22  1:34 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).