All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] ipv4: nexthop: handle errors in nexthop_init()
@ 2026-07-28  3:10 Minhong He
  2026-07-29 11:10 ` Ido Schimmel
  0 siblings, 1 reply; 2+ messages in thread
From: Minhong He @ 2026-07-28  3:10 UTC (permalink / raw)
  To: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, netdev
  Cc: linux-kernel

nexthop_init() ignores errors from register_pernet_subsys(),
register_netdevice_notifier() and rtnl_register_many(), so a partial
initialization can appear successful.

Check each step and unwind the registrations that already succeeded.

Signed-off-by: Minhong He <heminhong@kylinos.cn>
---
 net/ipv4/nexthop.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index 6205bd57aa85..0ad40d93e3b5 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -4192,12 +4192,26 @@ static const struct rtnl_msg_handler nexthop_rtnl_msg_handlers[] __initconst = {
 
 static int __init nexthop_init(void)
 {
-	register_pernet_subsys(&nexthop_net_ops);
+	int err;
+
+	err = register_pernet_subsys(&nexthop_net_ops);
+	if (err)
+		return err;
 
-	register_netdevice_notifier(&nh_netdev_notifier);
+	err = register_netdevice_notifier(&nh_netdev_notifier);
+	if (err)
+		goto err_unregister_pernet;
 
-	rtnl_register_many(nexthop_rtnl_msg_handlers);
+	err = rtnl_register_many(nexthop_rtnl_msg_handlers);
+	if (err)
+		goto err_unregister_notifier;
 
 	return 0;
+
+err_unregister_notifier:
+	unregister_netdevice_notifier(&nh_netdev_notifier);
+err_unregister_pernet:
+	unregister_pernet_subsys(&nexthop_net_ops);
+	return err;
 }
 subsys_initcall(nexthop_init);
-- 
2.25.1


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

* Re: [PATCH net] ipv4: nexthop: handle errors in nexthop_init()
  2026-07-28  3:10 [PATCH net] ipv4: nexthop: handle errors in nexthop_init() Minhong He
@ 2026-07-29 11:10 ` Ido Schimmel
  0 siblings, 0 replies; 2+ messages in thread
From: Ido Schimmel @ 2026-07-29 11:10 UTC (permalink / raw)
  To: Minhong He
  Cc: David Ahern, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, netdev, linux-kernel

On Tue, Jul 28, 2026 at 11:10:55AM +0800, Minhong He wrote:
> nexthop_init() ignores errors from register_pernet_subsys(),
> register_netdevice_notifier() and rtnl_register_many(), so a partial
> initialization can appear successful.
> 
> Check each step and unwind the registrations that already succeeded.
> 
> Signed-off-by: Minhong He <heminhong@kylinos.cn>
> ---
>  net/ipv4/nexthop.c | 20 +++++++++++++++++---
>  1 file changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
> index 6205bd57aa85..0ad40d93e3b5 100644
> --- a/net/ipv4/nexthop.c
> +++ b/net/ipv4/nexthop.c
> @@ -4192,12 +4192,26 @@ static const struct rtnl_msg_handler nexthop_rtnl_msg_handlers[] __initconst = {
>  
>  static int __init nexthop_init(void)
>  {
> -	register_pernet_subsys(&nexthop_net_ops);
> +	int err;
> +
> +	err = register_pernet_subsys(&nexthop_net_ops);
> +	if (err)
> +		return err;

This can only fail if the allocation of devhash didn't succeed, which
seems unlikely (boot + GFP_KERNEL), but OK.

>  
> -	register_netdevice_notifier(&nh_netdev_notifier);
> +	err = register_netdevice_notifier(&nh_netdev_notifier);
> +	if (err)
> +		goto err_unregister_pernet;

Can only fail if the notifier is already registered (not possible) or if
the NETDEV_{REGISTER,UP} replay fails which is also not possible given
that nh_netdev_event() always returns NOTIFY_DONE, but let's assume that
it's fragile and we can't rely on that.

>  
> -	rtnl_register_many(nexthop_rtnl_msg_handlers);
> +	err = rtnl_register_many(nexthop_rtnl_msg_handlers);
> +	if (err)
> +		goto err_unregister_notifier;

Panics upon failure.

So, I think you should drop the error handling from rtnl_register_many()
(explain why it can't fail in the commit message) and target net-next
given the lack of fixes tag and that the issue is theoretical.

>  
>  	return 0;
> +
> +err_unregister_notifier:
> +	unregister_netdevice_notifier(&nh_netdev_notifier);
> +err_unregister_pernet:
> +	unregister_pernet_subsys(&nexthop_net_ops);
> +	return err;
>  }
>  subsys_initcall(nexthop_init);
> -- 
> 2.25.1
> 

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

end of thread, other threads:[~2026-07-29 11:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-28  3:10 [PATCH net] ipv4: nexthop: handle errors in nexthop_init() Minhong He
2026-07-29 11:10 ` Ido Schimmel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.