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

Commit 4597c38

Browse files
q2vengregkh
authored andcommitted
mpls: Handle error of rtnl_register_module().
[ Upstream commit 5be2062 ] 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent ff7abcc commit 4597c38

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
@@ -2729,6 +2729,15 @@ static struct rtnl_af_ops mpls_af_ops __read_mostly = {
27292729
.get_stats_af_size = mpls_get_stats_af_size,
27302730
};
27312731

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

27482757
rtnl_af_register(&mpls_af_ops);
27492758

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

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

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

0 commit comments

Comments
 (0)