Skip to content

Commit 2ddc0dd

Browse files
Wen GuPaolo Abeni
authored andcommitted
net/smc: fix neighbour and rtable leak in smc_ib_find_route()
In smc_ib_find_route(), the neighbour found by neigh_lookup() and rtable resolved by ip_route_output_flow() are not released or put before return. It may cause the refcount leak, so fix it. Link: https://lore.kernel.org/r/20240506015439.108739-1-guwen@linux.alibaba.com Fixes: e5c4744 ("net/smc: add SMC-Rv2 connection establishment") Signed-off-by: Wen Gu <guwen@linux.alibaba.com> Link: https://lore.kernel.org/r/20240507125331.2808-1-guwen@linux.alibaba.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 4db783d commit 2ddc0dd

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

net/smc/smc_ib.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,18 @@ int smc_ib_find_route(struct net *net, __be32 saddr, __be32 daddr,
209209
if (IS_ERR(rt))
210210
goto out;
211211
if (rt->rt_uses_gateway && rt->rt_gw_family != AF_INET)
212-
goto out;
213-
neigh = rt->dst.ops->neigh_lookup(&rt->dst, NULL, &fl4.daddr);
214-
if (neigh) {
215-
memcpy(nexthop_mac, neigh->ha, ETH_ALEN);
216-
*uses_gateway = rt->rt_uses_gateway;
217-
return 0;
218-
}
212+
goto out_rt;
213+
neigh = dst_neigh_lookup(&rt->dst, &fl4.daddr);
214+
if (!neigh)
215+
goto out_rt;
216+
memcpy(nexthop_mac, neigh->ha, ETH_ALEN);
217+
*uses_gateway = rt->rt_uses_gateway;
218+
neigh_release(neigh);
219+
ip_rt_put(rt);
220+
return 0;
221+
222+
out_rt:
223+
ip_rt_put(rt);
219224
out:
220225
return -ENOENT;
221226
}

0 commit comments

Comments
 (0)