Re: [PATCH net] ipv4: nexthop: handle errors in nexthop_init()
From: Ido Schimmel
Date: Wed Jul 29 2026 - 07:48:55 EST
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@xxxxxxxxxx>
> ---
> 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
>