2019-11-19 06:04:58

by Sun Ke

[permalink] [raw]
Subject: [v2] nbd:fix memory leak in nbd_get_socket()

Before return NULL,put the sock first.

Cc: [email protected]
Fixes: cf1b2326b734 ("nbd: verify socket is supported during setup")
Signed-off-by: Sun Ke <[email protected]>
---
v2: add cc:stable tag
---
drivers/block/nbd.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index a94ee45..19e7599 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -993,6 +993,7 @@ static struct socket *nbd_get_socket(struct nbd_device *nbd, unsigned long fd,
if (sock->ops->shutdown == sock_no_shutdown) {
dev_err(disk_to_dev(nbd->disk), "Unsupported socket: shutdown callout must be supported.\n");
*err = -EINVAL;
+ sockfd_put(sock);
return NULL;
}

--
2.7.4


2019-11-19 16:15:55

by Jens Axboe

[permalink] [raw]
Subject: Re: [v2] nbd:fix memory leak in nbd_get_socket()

On 11/18/19 11:09 PM, Sun Ke wrote:
> Before return NULL,put the sock first.
>
> Cc: [email protected]
> Fixes: cf1b2326b734 ("nbd: verify socket is supported during setup")
> Signed-off-by: Sun Ke <[email protected]>

Please always CC the author of the patch you're fixing.

Mike, Josef - we probably need to get this upstream ASAP.

> ---
> v2: add cc:stable tag
> ---
> drivers/block/nbd.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
> index a94ee45..19e7599 100644
> --- a/drivers/block/nbd.c
> +++ b/drivers/block/nbd.c
> @@ -993,6 +993,7 @@ static struct socket *nbd_get_socket(struct nbd_device *nbd, unsigned long fd,
> if (sock->ops->shutdown == sock_no_shutdown) {
> dev_err(disk_to_dev(nbd->disk), "Unsupported socket: shutdown callout must be supported.\n");
> *err = -EINVAL;
> + sockfd_put(sock);
> return NULL;
> }
>
>


--
Jens Axboe


2019-11-19 16:18:59

by Josef Bacik

[permalink] [raw]
Subject: Re: [v2] nbd:fix memory leak in nbd_get_socket()

On Tue, Nov 19, 2019 at 09:13:34AM -0700, Jens Axboe wrote:
> On 11/18/19 11:09 PM, Sun Ke wrote:
> > Before return NULL,put the sock first.
> >
> > Cc: [email protected]
> > Fixes: cf1b2326b734 ("nbd: verify socket is supported during setup")
> > Signed-off-by: Sun Ke <[email protected]>
>
> Please always CC the author of the patch you're fixing.
>
> Mike, Josef - we probably need to get this upstream ASAP.

Yup sorry got distracted,

Reviewed-by: Josef Bacik <[email protected]>

Thanks,

Josef

2019-11-19 16:26:04

by Jens Axboe

[permalink] [raw]
Subject: Re: [v2] nbd:fix memory leak in nbd_get_socket()

On 11/19/19 9:22 AM, Mike Christie wrote:
> On 11/19/2019 12:09 AM, Sun Ke wrote:
>> Before return NULL,put the sock first.
>>
>> Cc: [email protected]
>> Fixes: cf1b2326b734 ("nbd: verify socket is supported during setup")
>> Signed-off-by: Sun Ke <[email protected]>
>> ---
>> v2: add cc:stable tag
>> ---
>> drivers/block/nbd.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
>> index a94ee45..19e7599 100644
>> --- a/drivers/block/nbd.c
>> +++ b/drivers/block/nbd.c
>> @@ -993,6 +993,7 @@ static struct socket *nbd_get_socket(struct nbd_device *nbd, unsigned long fd,
>> if (sock->ops->shutdown == sock_no_shutdown) {
>> dev_err(disk_to_dev(nbd->disk), "Unsupported socket: shutdown callout must be supported.\n");
>> *err = -EINVAL;
>> + sockfd_put(sock);
>> return NULL;
>> }
>>
>>
>
> Reviewed-by: Mike Christie <[email protected]>

Thanks (both of you), applied for 5.4.

--
Jens Axboe


2019-11-19 16:27:08

by Mike Christie

[permalink] [raw]
Subject: Re: [v2] nbd:fix memory leak in nbd_get_socket()

On 11/19/2019 12:09 AM, Sun Ke wrote:
> Before return NULL,put the sock first.
>
> Cc: [email protected]
> Fixes: cf1b2326b734 ("nbd: verify socket is supported during setup")
> Signed-off-by: Sun Ke <[email protected]>
> ---
> v2: add cc:stable tag
> ---
> drivers/block/nbd.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
> index a94ee45..19e7599 100644
> --- a/drivers/block/nbd.c
> +++ b/drivers/block/nbd.c
> @@ -993,6 +993,7 @@ static struct socket *nbd_get_socket(struct nbd_device *nbd, unsigned long fd,
> if (sock->ops->shutdown == sock_no_shutdown) {
> dev_err(disk_to_dev(nbd->disk), "Unsupported socket: shutdown callout must be supported.\n");
> *err = -EINVAL;
> + sockfd_put(sock);
> return NULL;
> }
>
>

Reviewed-by: Mike Christie <[email protected]>