Skip to content

Commit b6b638b

Browse files
idoschkuba-moo
authored andcommitted
mlxsw: spectrum_router: Fix possible neighbour reference count leak
mlxsw_sp_router_schedule_work() takes a reference on a neighbour, expecting a work item to release it later on. However, we might fail to schedule the work item, in which case the neighbour reference count will be leaked. Fix by taking the reference just before scheduling the work item. Note that mlxsw_sp_router_schedule_work() can receive a NULL neighbour pointer, but neigh_clone() handles that correctly. Spotted during code review, did not actually observe the reference count leak. Fixes: 151b89f ("mlxsw: spectrum_router: Reuse work neighbor initialization in work scheduler") Reviewed-by: Petr Machata <petrm@nvidia.com> Signed-off-by: Ido Schimmel <idosch@nvidia.com> Signed-off-by: Petr Machata <petrm@nvidia.com> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/ec2934ae4aca187a8d8c9329a08ce93cca411378.1764695650.git.petrm@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent c4cdf73 commit b6b638b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,6 +2858,11 @@ static int mlxsw_sp_router_schedule_work(struct net *net,
28582858
if (!net_work)
28592859
return NOTIFY_BAD;
28602860

2861+
/* Take a reference to ensure the neighbour won't be destructed until
2862+
* we drop the reference in the work item.
2863+
*/
2864+
neigh_clone(n);
2865+
28612866
INIT_WORK(&net_work->work, cb);
28622867
net_work->mlxsw_sp = router->mlxsw_sp;
28632868
net_work->n = n;
@@ -2881,11 +2886,6 @@ static int mlxsw_sp_router_schedule_neigh_work(struct mlxsw_sp_router *router,
28812886
struct net *net;
28822887

28832888
net = neigh_parms_net(n->parms);
2884-
2885-
/* Take a reference to ensure the neighbour won't be destructed until we
2886-
* drop the reference in delayed work.
2887-
*/
2888-
neigh_clone(n);
28892889
return mlxsw_sp_router_schedule_work(net, router, n,
28902890
mlxsw_sp_router_neigh_event_work);
28912891
}

0 commit comments

Comments
 (0)