[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <01dd166d-ab47-415c-bf80-6dff4f2a3d2b@linux.ibm.com>
Date: Tue, 7 May 2024 15:12:39 +0200
From: Wenjia Zhang <wenjia@...ux.ibm.com>
To: Wen Gu <guwen@...ux.alibaba.com>, jaka@...ux.ibm.com, davem@...emloft.net,
edumazet@...gle.com, kuba@...nel.org, pabeni@...hat.com
Cc: kgraul@...ux.ibm.com, alibuda@...ux.alibaba.com, tonylu@...ux.alibaba.com,
linux-s390@...r.kernel.org, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH net v2] net/smc: fix neighbour and rtable leak in
smc_ib_find_route()
On 07.05.24 14:53, Wen Gu wrote:
> 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: e5c4744cfb59 ("net/smc: add SMC-Rv2 connection establishment")
> Signed-off-by: Wen Gu <guwen@...ux.alibaba.com>
> ---
> v2->v1
> - call ip_rt_put() to release rt as well.
> ---
> net/smc/smc_ib.c | 19 ++++++++++++-------
> 1 file changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/net/smc/smc_ib.c b/net/smc/smc_ib.c
> index 97704a9e84c7..9297dc20bfe2 100644
> --- a/net/smc/smc_ib.c
> +++ b/net/smc/smc_ib.c
> @@ -209,13 +209,18 @@ int smc_ib_find_route(struct net *net, __be32 saddr, __be32 daddr,
> if (IS_ERR(rt))
> goto out;
> if (rt->rt_uses_gateway && rt->rt_gw_family != AF_INET)
> - goto out;
> - neigh = rt->dst.ops->neigh_lookup(&rt->dst, NULL, &fl4.daddr);
> - if (neigh) {
> - memcpy(nexthop_mac, neigh->ha, ETH_ALEN);
> - *uses_gateway = rt->rt_uses_gateway;
> - return 0;
> - }
> + goto out_rt;
> + neigh = dst_neigh_lookup(&rt->dst, &fl4.daddr);
> + if (!neigh)
> + goto out_rt;
> + memcpy(nexthop_mac, neigh->ha, ETH_ALEN);
> + *uses_gateway = rt->rt_uses_gateway;
> + neigh_release(neigh);
> + ip_rt_put(rt);
> + return 0;
> +
> +out_rt:
> + ip_rt_put(rt);
> out:
> return -ENOENT;
> }
Thank you for fixing it!
Reviewed-and-tested-by: Wenjia Zhang <wenjia@...ux.ibm.com>
Powered by blists - more mailing lists