linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] RDMA/ucma: Fix resource leak on error path
@ 2020-09-02 16:24 Alex Dewar
  2020-09-02 20:10 ` Jason Gunthorpe
  2020-09-03  0:34 ` Gustavo A. R. Silva
  0 siblings, 2 replies; 6+ messages in thread
From: Alex Dewar @ 2020-09-02 16:24 UTC (permalink / raw)
  Cc: Alex Dewar, Doug Ledford, Jason Gunthorpe, Leon Romanovsky,
	linux-rdma, linux-kernel

In ucma_process_join(), if the call to xa_alloc() fails, the function
will return without freeing mc. Fix this by jumping to the correct line.

In the process I renamed the jump labels to something more memorable for
extra clarity.

Addresses-Coverity: ("Resource leak")
Fixes: 95fe51096b7a ("RDMA/ucma: Remove mc_list and rely on xarray")
Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>
---
 drivers/infiniband/core/ucma.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
index f2c9ef6ae481..a5595bd489b0 100644
--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -1453,7 +1453,7 @@ static ssize_t ucma_process_join(struct ucma_file *file,
 	mc = kzalloc(sizeof(*mc), GFP_KERNEL);
 	if (!mc) {
 		ret = -ENOMEM;
-		goto err1;
+		goto err_put_ctx;
 	}
 
 	mc->ctx = ctx;
@@ -1464,7 +1464,7 @@ static ssize_t ucma_process_join(struct ucma_file *file,
 	if (xa_alloc(&multicast_table, &mc->id, NULL, xa_limit_32b,
 		     GFP_KERNEL)) {
 		ret = -ENOMEM;
-		goto err1;
+		goto err_free_mc;
 	}
 
 	mutex_lock(&ctx->mutex);
@@ -1472,13 +1472,13 @@ static ssize_t ucma_process_join(struct ucma_file *file,
 				  join_state, mc);
 	mutex_unlock(&ctx->mutex);
 	if (ret)
-		goto err2;
+		goto err_xa_erase;
 
 	resp.id = mc->id;
 	if (copy_to_user(u64_to_user_ptr(cmd->response),
 			 &resp, sizeof(resp))) {
 		ret = -EFAULT;
-		goto err3;
+		goto err_leave_multicast;
 	}
 
 	xa_store(&multicast_table, mc->id, mc, 0);
@@ -1486,15 +1486,16 @@ static ssize_t ucma_process_join(struct ucma_file *file,
 	ucma_put_ctx(ctx);
 	return 0;
 
-err3:
+err_leave_multicast:
 	mutex_lock(&ctx->mutex);
 	rdma_leave_multicast(ctx->cm_id, (struct sockaddr *) &mc->addr);
 	mutex_unlock(&ctx->mutex);
 	ucma_cleanup_mc_events(mc);
-err2:
+err_xa_erase:
 	xa_erase(&multicast_table, mc->id);
+err_free_mc:
 	kfree(mc);
-err1:
+err_put_ctx:
 	ucma_put_ctx(ctx);
 	return ret;
 }
-- 
2.28.0


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

* Re: [PATCH] RDMA/ucma: Fix resource leak on error path
  2020-09-02 16:24 [PATCH] RDMA/ucma: Fix resource leak on error path Alex Dewar
@ 2020-09-02 20:10 ` Jason Gunthorpe
  2020-09-03  0:34 ` Gustavo A. R. Silva
  1 sibling, 0 replies; 6+ messages in thread
From: Jason Gunthorpe @ 2020-09-02 20:10 UTC (permalink / raw)
  To: Alex Dewar; +Cc: Doug Ledford, Leon Romanovsky, linux-rdma, linux-kernel

On Wed, Sep 02, 2020 at 05:24:51PM +0100, Alex Dewar wrote:
> In ucma_process_join(), if the call to xa_alloc() fails, the function
> will return without freeing mc. Fix this by jumping to the correct line.
> 
> In the process I renamed the jump labels to something more memorable for
> extra clarity.
> 
> Addresses-Coverity: ("Resource leak")
> Fixes: 95fe51096b7a ("RDMA/ucma: Remove mc_list and rely on xarray")
> Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>

Applied to for-next, thanks

Jason

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

* Re: [PATCH] RDMA/ucma: Fix resource leak on error path
  2020-09-03  0:34 ` Gustavo A. R. Silva
@ 2020-09-03  0:32   ` Jason Gunthorpe
  2020-09-03  0:40     ` Gustavo A. R. Silva
  2020-09-03  9:35   ` Alex Dewar
  1 sibling, 1 reply; 6+ messages in thread
From: Jason Gunthorpe @ 2020-09-03  0:32 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Alex Dewar, Doug Ledford, Leon Romanovsky, linux-rdma, linux-kernel

On Wed, Sep 02, 2020 at 07:34:26PM -0500, Gustavo A. R. Silva wrote:
> Hi Alex,
> 
> On 9/2/20 11:24, Alex Dewar wrote:
> > In ucma_process_join(), if the call to xa_alloc() fails, the function
> > will return without freeing mc. Fix this by jumping to the correct line.
> > 
> > In the process I renamed the jump labels to something more memorable for
> > extra clarity.
> > 
> > Addresses-Coverity: ("Resource leak")
> 
> If you are using a public Coverity scan, please also include the Coverity ID.
> In this case ID 1496814, something like:
> 
> Addresses-Coverity-ID: 1496814 ("Resource leak")

Thanks, I fixed it up

Jason

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

* Re: [PATCH] RDMA/ucma: Fix resource leak on error path
  2020-09-02 16:24 [PATCH] RDMA/ucma: Fix resource leak on error path Alex Dewar
  2020-09-02 20:10 ` Jason Gunthorpe
@ 2020-09-03  0:34 ` Gustavo A. R. Silva
  2020-09-03  0:32   ` Jason Gunthorpe
  2020-09-03  9:35   ` Alex Dewar
  1 sibling, 2 replies; 6+ messages in thread
From: Gustavo A. R. Silva @ 2020-09-03  0:34 UTC (permalink / raw)
  To: Alex Dewar
  Cc: Doug Ledford, Jason Gunthorpe, Leon Romanovsky, linux-rdma, linux-kernel

Hi Alex,

On 9/2/20 11:24, Alex Dewar wrote:
> In ucma_process_join(), if the call to xa_alloc() fails, the function
> will return without freeing mc. Fix this by jumping to the correct line.
> 
> In the process I renamed the jump labels to something more memorable for
> extra clarity.
> 
> Addresses-Coverity: ("Resource leak")

If you are using a public Coverity scan, please also include the Coverity ID.
In this case ID 1496814, something like:

Addresses-Coverity-ID: 1496814 ("Resource leak")

People that don't include an CID is because they are using a private Coverity
scan, so it doesn't make sense for them to add an ID because no one but
them have access to that scan report.

Thanks
--
Gustavo


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

* Re: [PATCH] RDMA/ucma: Fix resource leak on error path
  2020-09-03  0:32   ` Jason Gunthorpe
@ 2020-09-03  0:40     ` Gustavo A. R. Silva
  0 siblings, 0 replies; 6+ messages in thread
From: Gustavo A. R. Silva @ 2020-09-03  0:40 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alex Dewar, Doug Ledford, Leon Romanovsky, linux-rdma, linux-kernel


On 9/2/20 19:32, Jason Gunthorpe wrote:

>>> Addresses-Coverity: ("Resource leak")
>>
>> If you are using a public Coverity scan, please also include the Coverity ID.
>> In this case ID 1496814, something like:
>>
>> Addresses-Coverity-ID: 1496814 ("Resource leak")
> 
> Thanks, I fixed it up
> 

Awesome. :)

Thanks, Jason.
--
Gustavo

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

* Re: [PATCH] RDMA/ucma: Fix resource leak on error path
  2020-09-03  0:34 ` Gustavo A. R. Silva
  2020-09-03  0:32   ` Jason Gunthorpe
@ 2020-09-03  9:35   ` Alex Dewar
  1 sibling, 0 replies; 6+ messages in thread
From: Alex Dewar @ 2020-09-03  9:35 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Alex Dewar, Doug Ledford, Jason Gunthorpe, Leon Romanovsky,
	linux-rdma, linux-kernel

On Wed, Sep 02, 2020 at 07:34:26PM -0500, Gustavo A. R. Silva wrote:
> Hi Alex,
> 
> On 9/2/20 11:24, Alex Dewar wrote:
> > In ucma_process_join(), if the call to xa_alloc() fails, the function
> > will return without freeing mc. Fix this by jumping to the correct line.
> > 
> > In the process I renamed the jump labels to something more memorable for
> > extra clarity.
> > 
> > Addresses-Coverity: ("Resource leak")
> 
> If you are using a public Coverity scan, please also include the Coverity ID.
> In this case ID 1496814, something like:
> 
> Addresses-Coverity-ID: 1496814 ("Resource leak")

Ahh ok. Thanks for the pointer :)
> 
> People that don't include an CID is because they are using a private Coverity
> scan, so it doesn't make sense for them to add an ID because no one but
> them have access to that scan report.
> 
> Thanks
> --
> Gustavo
> 

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

end of thread, other threads:[~2020-09-03  9:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-02 16:24 [PATCH] RDMA/ucma: Fix resource leak on error path Alex Dewar
2020-09-02 20:10 ` Jason Gunthorpe
2020-09-03  0:34 ` Gustavo A. R. Silva
2020-09-03  0:32   ` Jason Gunthorpe
2020-09-03  0:40     ` Gustavo A. R. Silva
2020-09-03  9:35   ` Alex Dewar

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).