Skip to contentSkip to conversation

ipv6: route: Unregister netdevice notifier on BPF init failure

PATCH Superseded Yuho Choi 2 participants 2 messages May 14 – May 15

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 ipv6: route: Unregister netdevice notifier on BPF init failure

ip6_route_init() registers ip6_route_dev_notifier before registering the IPv6 route BPF iterator target. If bpf_iter_register() fails, the error path jumps to out_register_late_subsys and unwinds the RTNL handlers and late pernet subsystem, but leaves the netdevice notifier registered.

Add a separate unwind label for the BPF iterator failure path so the netdevice notifier is unregistered before continuing with the existing cleanup.

Fixes 138d0be35b14 ("net: bpf: Add netlink and ipv6_route bpf_iter targets")
---
 net/ipv6/route.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
net/ipv6/route.c +7 -1
index cb521700cee7..4333e11dc9c5 100644
@@ -6925,7 +6925,7 @@ int __init ip6_route_init(void)
 #if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_PROC_FS)
 	ret = bpf_iter_register();
 	if (ret)
-		goto out_register_late_subsys;
+		goto out_register_notifier;
 #endif
 #endif
 
@@ -6939,6 +6939,12 @@ int __init ip6_route_init(void)
 out:
 	return ret;
 
+#if IS_BUILTIN(CONFIG_IPV6)
+#if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_PROC_FS)
+out_register_notifier:
+	unregister_netdevice_notifier(&ip6_route_dev_notifier);
+#endif
+#endif
 out_register_late_subsys:
 	rtnl_unregister_all(PF_INET6);
 	unregister_pernet_subsys(&ip6_route_net_late_ops);
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 26 lines · On Wed, 13 May 2026 20:22:18 -0400 Yuho Choi wrote:

ip6_route_init() registers ip6_route_dev_notifier before registering the IPv6 route BPF iterator target. If bpf_iter_register() fails, the error path jumps to out_register_late_subsys and unwinds the RTNL handlers and late pernet subsystem, but leaves the netdevice notifier registered.

Add a separate unwind label for the BPF iterator failure path so the netdevice notifier is unregistered before continuing with the existing cleanup.

Fixes 138d0be35b14 ("net: bpf: Add netlink and ipv6_route bpf_iter targets")
net/ipv6/route.c +1 -1
index cb521700cee7..4333e11dc9c5 100644
@@ -6925,7 +6925,7 @@ int __init ip6_route_init(void)
 #if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_PROC_FS)
 	ret = bpf_iter_register();
 	if (ret)
-		goto out_register_late_subsys;
+		goto out_register_notifier;
 #endif
 #endif
 

net/ipv6/route.c int __init ip6_route_init(void) · line 6942

Quoted 4 lines
net/ipv6/route.c +1 -0
@@ -6939,6 +6939,12 @@ int __init ip6_route_init(void)
 out:
 	return ret;
 
+#if IS_BUILTIN(CONFIG_IPV6)

Why this check?

Quoted 5 lines
net/ipv6/route.c +5 -0
+#if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_PROC_FS)
+out_register_notifier:
+	unregister_netdevice_notifier(&ip6_route_dev_notifier);
+#endif
+#endif
Signature · 1 line
pw-bot: cr