Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 5be2062

Browse files
q2venPaolo Abeni
authored andcommitted
mpls: Handle error of rtnl_register_module().
Since introduced, mpls_init() has been ignoring the returned value of rtnl_register_module(), which could fail silently. Handling the error allows users to view a module as an all-or-nothing thing in terms of the rtnetlink functionality. This prevents syzkaller from reporting spurious errors from its tests, where OOM often occurs and module is automatically loaded. Let's handle the errors by rtnl_register_many(). Fixes: 03c0566 ("mpls: Netlink commands to add, remove, and dump routes") Signed-off-by: Kuniyuki Iwashima <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent d517056 commit 5be2062

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

net/mpls/af_mpls.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,6 +2728,15 @@ static struct rtnl_af_ops mpls_af_ops __read_mostly = {
27282728
.get_stats_af_size = mpls_get_stats_af_size,
27292729
};
27302730

2731+
static const struct rtnl_msg_handler mpls_rtnl_msg_handlers[] __initdata_or_module = {
2732+
{THIS_MODULE, PF_MPLS, RTM_NEWROUTE, mpls_rtm_newroute, NULL, 0},
2733+
{THIS_MODULE, PF_MPLS, RTM_DELROUTE, mpls_rtm_delroute, NULL, 0},
2734+
{THIS_MODULE, PF_MPLS, RTM_GETROUTE, mpls_getroute, mpls_dump_routes, 0},
2735+
{THIS_MODULE, PF_MPLS, RTM_GETNETCONF,
2736+
mpls_netconf_get_devconf, mpls_netconf_dump_devconf,
2737+
RTNL_FLAG_DUMP_UNLOCKED},
2738+
};
2739+
27312740
static int __init mpls_init(void)
27322741
{
27332742
int err;
@@ -2746,24 +2755,25 @@ static int __init mpls_init(void)
27462755

27472756
rtnl_af_register(&mpls_af_ops);
27482757

2749-
rtnl_register_module(THIS_MODULE, PF_MPLS, RTM_NEWROUTE,
2750-
mpls_rtm_newroute, NULL, 0);
2751-
rtnl_register_module(THIS_MODULE, PF_MPLS, RTM_DELROUTE,
2752-
mpls_rtm_delroute, NULL, 0);
2753-
rtnl_register_module(THIS_MODULE, PF_MPLS, RTM_GETROUTE,
2754-
mpls_getroute, mpls_dump_routes, 0);
2755-
rtnl_register_module(THIS_MODULE, PF_MPLS, RTM_GETNETCONF,
2756-
mpls_netconf_get_devconf,
2757-
mpls_netconf_dump_devconf,
2758-
RTNL_FLAG_DUMP_UNLOCKED);
2759-
err = ipgre_tunnel_encap_add_mpls_ops();
2758+
err = rtnl_register_many(mpls_rtnl_msg_handlers);
27602759
if (err)
2760+
goto out_unregister_rtnl_af;
2761+
2762+
err = ipgre_tunnel_encap_add_mpls_ops();
2763+
if (err) {
27612764
pr_err("Can't add mpls over gre tunnel ops\n");
2765+
goto out_unregister_rtnl;
2766+
}
27622767

27632768
err = 0;
27642769
out:
27652770
return err;
27662771

2772+
out_unregister_rtnl:
2773+
rtnl_unregister_many(mpls_rtnl_msg_handlers);
2774+
out_unregister_rtnl_af:
2775+
rtnl_af_unregister(&mpls_af_ops);
2776+
dev_remove_pack(&mpls_packet_type);
27672777
out_unregister_pernet:
27682778
unregister_pernet_subsys(&mpls_net_ops);
27692779
goto out;

0 commit comments

Comments
 (0)