linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nbd: prevent memory leak
@ 2019-09-23 20:09 Navid Emamdoost
  2019-11-21 18:24 ` Navid Emamdoost
  2019-11-21 18:30 ` Josef Bacik
  0 siblings, 2 replies; 4+ messages in thread
From: Navid Emamdoost @ 2019-09-23 20:09 UTC (permalink / raw)
  Cc: emamd001, smccaman, kjlu, Navid Emamdoost, Josef Bacik,
	Jens Axboe, linux-block, nbd, linux-kernel

In nbd_add_socket when krealloc succeeds, if nsock's allocation fail the
reallocted memory is leak. The correct behaviour should be assigning the
reallocted memory to config->socks right after success.

Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
 drivers/block/nbd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index a8e3815295fe..8ae3bd2e7b30 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -987,14 +987,15 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
 		sockfd_put(sock);
 		return -ENOMEM;
 	}
+
+	config->socks = socks;
+
 	nsock = kzalloc(sizeof(struct nbd_sock), GFP_KERNEL);
 	if (!nsock) {
 		sockfd_put(sock);
 		return -ENOMEM;
 	}
 
-	config->socks = socks;
-
 	nsock->fallback_index = -1;
 	nsock->dead = false;
 	mutex_init(&nsock->tx_lock);
-- 
2.17.1


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

* Re: [PATCH] nbd: prevent memory leak
  2019-09-23 20:09 [PATCH] nbd: prevent memory leak Navid Emamdoost
@ 2019-11-21 18:24 ` Navid Emamdoost
  2019-11-21 18:30 ` Josef Bacik
  1 sibling, 0 replies; 4+ messages in thread
From: Navid Emamdoost @ 2019-11-21 18:24 UTC (permalink / raw)
  To: Josef Bacik, Jens Axboe, linux-block, nbd; +Cc: Navid Emamdoost, LKML

On Mon, Sep 23, 2019 at 3:10 PM Navid Emamdoost
<navid.emamdoost@gmail.com> wrote:
>
> In nbd_add_socket when krealloc succeeds, if nsock's allocation fail the
> reallocted memory is leak. The correct behaviour should be assigning the
> reallocted memory to config->socks right after success.
>
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> ---

Would you please review this patch?

Thanks,

>  drivers/block/nbd.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
> index a8e3815295fe..8ae3bd2e7b30 100644
> --- a/drivers/block/nbd.c
> +++ b/drivers/block/nbd.c
> @@ -987,14 +987,15 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
>                 sockfd_put(sock);
>                 return -ENOMEM;
>         }
> +
> +       config->socks = socks;
> +
>         nsock = kzalloc(sizeof(struct nbd_sock), GFP_KERNEL);
>         if (!nsock) {
>                 sockfd_put(sock);
>                 return -ENOMEM;
>         }
>
> -       config->socks = socks;
> -
>         nsock->fallback_index = -1;
>         nsock->dead = false;
>         mutex_init(&nsock->tx_lock);
> --
> 2.17.1
>


-- 
Navid.

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

* Re: [PATCH] nbd: prevent memory leak
  2019-09-23 20:09 [PATCH] nbd: prevent memory leak Navid Emamdoost
  2019-11-21 18:24 ` Navid Emamdoost
@ 2019-11-21 18:30 ` Josef Bacik
  2019-11-21 18:37   ` Jens Axboe
  1 sibling, 1 reply; 4+ messages in thread
From: Josef Bacik @ 2019-11-21 18:30 UTC (permalink / raw)
  To: Navid Emamdoost
  Cc: emamd001, smccaman, kjlu, Josef Bacik, Jens Axboe, linux-block,
	nbd, linux-kernel

On Mon, Sep 23, 2019 at 03:09:58PM -0500, Navid Emamdoost wrote:
> In nbd_add_socket when krealloc succeeds, if nsock's allocation fail the
> reallocted memory is leak. The correct behaviour should be assigning the
> reallocted memory to config->socks right after success.
> 
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> ---

Reviewed-by: Josef Bacik <josef@toxicpanda.com>

Thanks,

Josef

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

* Re: [PATCH] nbd: prevent memory leak
  2019-11-21 18:30 ` Josef Bacik
@ 2019-11-21 18:37   ` Jens Axboe
  0 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2019-11-21 18:37 UTC (permalink / raw)
  To: Josef Bacik, Navid Emamdoost
  Cc: emamd001, smccaman, kjlu, linux-block, nbd, linux-kernel

On 11/21/19 11:30 AM, Josef Bacik wrote:
> On Mon, Sep 23, 2019 at 03:09:58PM -0500, Navid Emamdoost wrote:
>> In nbd_add_socket when krealloc succeeds, if nsock's allocation fail the
>> reallocted memory is leak. The correct behaviour should be assigning the
>> reallocted memory to config->socks right after success.
>>
>> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
>> ---
> 
> Reviewed-by: Josef Bacik <josef@toxicpanda.com>

Now applied, thanks.

-- 
Jens Axboe


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

end of thread, other threads:[~2019-11-21 18:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-23 20:09 [PATCH] nbd: prevent memory leak Navid Emamdoost
2019-11-21 18:24 ` Navid Emamdoost
2019-11-21 18:30 ` Josef Bacik
2019-11-21 18:37   ` Jens Axboe

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