Skip to contentSkip to conversation

rtnetlink: Use register_pernet_subsys() in rtnl_net_debug_init().

PATCH Applied Kuniyuki Iwashima 3 participants 3 messages Apr 1, 2025 – Apr 3, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 rtnetlink: Use register_pernet_subsys() in rtnl_net_debug_init().

rtnl_net_debug_init() registers rtnl_net_debug_net_ops by register_pernet_device() but calls unregister_pernet_subsys() in case register_netdevice_notifier() fails.

It corrupts pernet_list because first_device is updated in register_pernet_device() but not unregister_pernet_subsys().

Let's fix it by calling register_pernet_subsys() instead.

The _subsys() one fits better for the use case because it keeps the notifier alive until default_device_exit_net(), giving it more chance to test NETDEV_UNREGISTER.

Fixes 03fa53485659 ("rtnetlink: Add ASSERT_RTNL_NET() placeholder for netdev notifier.")

---
v2: Correct changelog
v1: https://lore.kernel.org/netdev/[email protected]/

---
 net/core/rtnl_net_debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/rtnl_net_debug.c +1 -1
index 7ecd28cc1c22..f3272b09c255 100644
@@ -102,7 +102,7 @@ static int __init rtnl_net_debug_init(void)
 {
 	int ret;
 
-	ret = register_pernet_device(&rtnl_net_debug_net_ops);
+	ret = register_pernet_subsys(&rtnl_net_debug_net_ops);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.48.1
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 13 lines · Kuniyuki Iwashima

rtnl_net_debug_init() registers rtnl_net_debug_net_ops by register_pernet_device() but calls unregister_pernet_subsys() in case register_netdevice_notifier() fails.

It corrupts pernet_list because first_device is updated in register_pernet_device() but not unregister_pernet_subsys().

Let's fix it by calling register_pernet_subsys() instead.

The _subsys() one fits better for the use case because it keeps the notifier alive until default_device_exit_net(), giving it more chance to test NETDEV_UNREGISTER.

Quoted 5 lines
Fixes 03fa53485659 ("rtnetlink: Add ASSERT_RTNL_NET() placeholder for netdev notifier.")

---
v2: Correct changelog
v1: https://lore.kernel.org/netdev/[email protected]/

Thanks for the update.

...

#2 lore raw
In reply to Kuniyuki Iwashima
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Tue, 1 Apr 2025 12:07:08 -0700 you wrote:

rtnl_net_debug_init() registers rtnl_net_debug_net_ops by register_pernet_device() but calls unregister_pernet_subsys() in case register_netdevice_notifier() fails.

It corrupts pernet_list because first_device is updated in register_pernet_device() but not unregister_pernet_subsys().

[...]

Here is the summary with links:
- [v2,net] rtnetlink: Use register_pernet_subsys() in rtnl_net_debug_init().

    https://git.kernel.org/netdev/net/c/1b7fdc702c03

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html