linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] SUNRPC: Fix potential memory leak in xs_udp_send_request()
@ 2022-09-07  7:13 Jianglei Nie
  2022-09-07 10:08 ` Jeff Layton
  0 siblings, 1 reply; 3+ messages in thread
From: Jianglei Nie @ 2022-09-07  7:13 UTC (permalink / raw)
  To: chuck.lever, jlayton, trond.myklebust, anna, davem, edumazet,
	kuba, pabeni
  Cc: linux-nfs, netdev, linux-kernel, Jianglei Nie

xs_udp_send_request() allocates a memory chunk for xdr->bvec with
xdr_alloc_bvec(). When xprt_sock_sendmsg() finishs, xdr->bvec is not
released, which will lead to a memory leak.

we should release the xdr->bvec with xdr_free_bvec() after
xprt_sock_sendmsg() like bc_sendto() does.

Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
---
 net/sunrpc/xprtsock.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index e976007f4fd0..298182a3c168 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -958,6 +958,7 @@ static int xs_udp_send_request(struct rpc_rqst *req)
 		return status;
 	req->rq_xtime = ktime_get();
 	status = xprt_sock_sendmsg(transport->sock, &msg, xdr, 0, 0, &sent);
+	xdr_free_bvec(xdr);
 
 	dprintk("RPC:       xs_udp_send_request(%u) = %d\n",
 			xdr->len, status);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] SUNRPC: Fix potential memory leak in xs_udp_send_request()
  2022-09-07  7:13 [PATCH] SUNRPC: Fix potential memory leak in xs_udp_send_request() Jianglei Nie
@ 2022-09-07 10:08 ` Jeff Layton
  2022-09-07 13:30   ` Trond Myklebust
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff Layton @ 2022-09-07 10:08 UTC (permalink / raw)
  To: Jianglei Nie, chuck.lever, trond.myklebust, anna, davem,
	edumazet, kuba, pabeni
  Cc: linux-nfs, netdev, linux-kernel

On Wed, 2022-09-07 at 15:13 +0800, Jianglei Nie wrote:
> xs_udp_send_request() allocates a memory chunk for xdr->bvec with
> xdr_alloc_bvec(). When xprt_sock_sendmsg() finishs, xdr->bvec is not
> released, which will lead to a memory leak.
> 
> we should release the xdr->bvec with xdr_free_bvec() after
> xprt_sock_sendmsg() like bc_sendto() does.
> 
> Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
> ---
>  net/sunrpc/xprtsock.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
> index e976007f4fd0..298182a3c168 100644
> --- a/net/sunrpc/xprtsock.c
> +++ b/net/sunrpc/xprtsock.c
> @@ -958,6 +958,7 @@ static int xs_udp_send_request(struct rpc_rqst *req)
>  		return status;
>  	req->rq_xtime = ktime_get();
>  	status = xprt_sock_sendmsg(transport->sock, &msg, xdr, 0, 0, &sent);
> +	xdr_free_bvec(xdr);
>  
>  	dprintk("RPC:       xs_udp_send_request(%u) = %d\n",
>  			xdr->len, status);

I think you're probably correct here.

I was thinking we might have a similar bug in svc_tcp_sendmsg, but it
looks like that one gets freed in svc_tcp_sendto.

Reviewed-by: Jeff Layton <jlayton@kernel.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] SUNRPC: Fix potential memory leak in xs_udp_send_request()
  2022-09-07 10:08 ` Jeff Layton
@ 2022-09-07 13:30   ` Trond Myklebust
  0 siblings, 0 replies; 3+ messages in thread
From: Trond Myklebust @ 2022-09-07 13:30 UTC (permalink / raw)
  To: niejianglei2021, davem, chuck.lever, anna, pabeni, jlayton,
	edumazet, kuba
  Cc: linux-nfs, netdev, linux-kernel

On Wed, 2022-09-07 at 06:08 -0400, Jeff Layton wrote:
> On Wed, 2022-09-07 at 15:13 +0800, Jianglei Nie wrote:
> > xs_udp_send_request() allocates a memory chunk for xdr->bvec with
> > xdr_alloc_bvec(). When xprt_sock_sendmsg() finishs, xdr->bvec is
> > not
> > released, which will lead to a memory leak.
> > 
> > we should release the xdr->bvec with xdr_free_bvec() after
> > xprt_sock_sendmsg() like bc_sendto() does.
> > 
> > Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
> > ---
> >  net/sunrpc/xprtsock.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
> > index e976007f4fd0..298182a3c168 100644
> > --- a/net/sunrpc/xprtsock.c
> > +++ b/net/sunrpc/xprtsock.c
> > @@ -958,6 +958,7 @@ static int xs_udp_send_request(struct rpc_rqst
> > *req)
> >                 return status;
> >         req->rq_xtime = ktime_get();
> >         status = xprt_sock_sendmsg(transport->sock, &msg, xdr, 0,
> > 0, &sent);
> > +       xdr_free_bvec(xdr);
> >  
> >         dprintk("RPC:       xs_udp_send_request(%u) = %d\n",
> >                         xdr->len, status);
> 
> I think you're probably correct here.
> 
> I was thinking we might have a similar bug in svc_tcp_sendmsg, but it
> looks like that one gets freed in svc_tcp_sendto.
> 
> Reviewed-by: Jeff Layton <jlayton@kernel.org>

No, this patch is unnecessary and won't be applied. We already do this
for all transports in xprt_request_dequeue_transmit().

-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trond.myklebust@hammerspace.com



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-07 13:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-07  7:13 [PATCH] SUNRPC: Fix potential memory leak in xs_udp_send_request() Jianglei Nie
2022-09-07 10:08 ` Jeff Layton
2022-09-07 13:30   ` Trond Myklebust

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).