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

Commit c246bfb

Browse files
q2vengregkh
authored andcommitted
phonet: Handle error of rtnl_register_module().
[ Upstream commit b5e837c ] Before commit addf9b9 ("net: rtnetlink: use rcu to free rtnl message handlers"), once the first rtnl_register_module() allocated rtnl_msg_handlers[PF_PHONET], the following calls never failed. However, after the commit, rtnl_register_module() could fail silently to allocate rtnl_msg_handlers[PF_PHONET][msgtype] and requires error handling for each call. 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 use rtnl_register_many() to handle the errors easily. Fixes: addf9b9 ("net: rtnetlink: use rcu to free rtnl message handlers") Signed-off-by: Kuniyuki Iwashima <[email protected]> Acked-by: Rémi Denis-Courmont <[email protected]> Signed-off-by: Paolo Abeni <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent a8e473f commit c246bfb

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

net/phonet/pn_netlink.c

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -285,23 +285,17 @@ static int route_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
285285
return err;
286286
}
287287

288+
static const struct rtnl_msg_handler phonet_rtnl_msg_handlers[] __initdata_or_module = {
289+
{THIS_MODULE, PF_PHONET, RTM_NEWADDR, addr_doit, NULL, 0},
290+
{THIS_MODULE, PF_PHONET, RTM_DELADDR, addr_doit, NULL, 0},
291+
{THIS_MODULE, PF_PHONET, RTM_GETADDR, NULL, getaddr_dumpit, 0},
292+
{THIS_MODULE, PF_PHONET, RTM_NEWROUTE, route_doit, NULL, 0},
293+
{THIS_MODULE, PF_PHONET, RTM_DELROUTE, route_doit, NULL, 0},
294+
{THIS_MODULE, PF_PHONET, RTM_GETROUTE, NULL, route_dumpit,
295+
RTNL_FLAG_DUMP_UNLOCKED},
296+
};
297+
288298
int __init phonet_netlink_register(void)
289299
{
290-
int err = rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_NEWADDR,
291-
addr_doit, NULL, 0);
292-
if (err)
293-
return err;
294-
295-
/* Further rtnl_register_module() cannot fail */
296-
rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_DELADDR,
297-
addr_doit, NULL, 0);
298-
rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_GETADDR,
299-
NULL, getaddr_dumpit, 0);
300-
rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_NEWROUTE,
301-
route_doit, NULL, 0);
302-
rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_DELROUTE,
303-
route_doit, NULL, 0);
304-
rtnl_register_module(THIS_MODULE, PF_PHONET, RTM_GETROUTE,
305-
NULL, route_dumpit, RTNL_FLAG_DUMP_UNLOCKED);
306-
return 0;
300+
return rtnl_register_many(phonet_rtnl_msg_handlers);
307301
}

0 commit comments

Comments
 (0)