linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vfio: fix potential memory leak in vfio_msi_cap_len
@ 2018-08-27 12:47 Li Qiang
  2018-08-30 14:15 ` David Hildenbrand
  2018-09-04 15:52 ` Alex Williamson
  0 siblings, 2 replies; 4+ messages in thread
From: Li Qiang @ 2018-08-27 12:47 UTC (permalink / raw)
  To: alex.williamson, eric.auger; +Cc: kvm, linux-kernel, liqiang02, Li Qiang

Free the vdev->msi_perm in error path.

Signed-off-by: Li Qiang <liq3ea@gmail.com>
---
 drivers/vfio/pci/vfio_pci_config.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
index 115a36f6f403..62023b4a373b 100644
--- a/drivers/vfio/pci/vfio_pci_config.c
+++ b/drivers/vfio/pci/vfio_pci_config.c
@@ -1180,8 +1180,10 @@ static int vfio_msi_cap_len(struct vfio_pci_device *vdev, u8 pos)
 		return -ENOMEM;
 
 	ret = init_pci_cap_msi_perm(vdev->msi_perm, len, flags);
-	if (ret)
+	if (ret) {
+		kfree(vdev->msi_perm);
 		return ret;
+	}
 
 	return len;
 }
-- 
2.11.0


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

* Re: [PATCH] vfio: fix potential memory leak in vfio_msi_cap_len
  2018-08-27 12:47 [PATCH] vfio: fix potential memory leak in vfio_msi_cap_len Li Qiang
@ 2018-08-30 14:15 ` David Hildenbrand
  2018-09-03 17:00   ` Auger Eric
  2018-09-04 15:52 ` Alex Williamson
  1 sibling, 1 reply; 4+ messages in thread
From: David Hildenbrand @ 2018-08-30 14:15 UTC (permalink / raw)
  To: Li Qiang, alex.williamson, eric.auger; +Cc: kvm, linux-kernel, liqiang02

On 27.08.2018 14:47, Li Qiang wrote:
> Free the vdev->msi_perm in error path.
> 
> Signed-off-by: Li Qiang <liq3ea@gmail.com>
> ---
>  drivers/vfio/pci/vfio_pci_config.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
> index 115a36f6f403..62023b4a373b 100644
> --- a/drivers/vfio/pci/vfio_pci_config.c
> +++ b/drivers/vfio/pci/vfio_pci_config.c
> @@ -1180,8 +1180,10 @@ static int vfio_msi_cap_len(struct vfio_pci_device *vdev, u8 pos)
>  		return -ENOMEM;
>  
>  	ret = init_pci_cap_msi_perm(vdev->msi_perm, len, flags);
> -	if (ret)
> +	if (ret) {
> +		kfree(vdev->msi_perm);
>  		return ret;
> +	}
>  
>  	return len;
>  }
> 

Doesn't vfio_config_free() take care of that in all cases?

-- 

Thanks,

David / dhildenb

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

* Re: [PATCH] vfio: fix potential memory leak in vfio_msi_cap_len
  2018-08-30 14:15 ` David Hildenbrand
@ 2018-09-03 17:00   ` Auger Eric
  0 siblings, 0 replies; 4+ messages in thread
From: Auger Eric @ 2018-09-03 17:00 UTC (permalink / raw)
  To: David Hildenbrand, Li Qiang, alex.williamson; +Cc: kvm, linux-kernel, liqiang02

Hi Li, David,

On 08/30/2018 04:15 PM, David Hildenbrand wrote:
> On 27.08.2018 14:47, Li Qiang wrote:
>> Free the vdev->msi_perm in error path.
>>
>> Signed-off-by: Li Qiang <liq3ea@gmail.com>
>> ---
>>  drivers/vfio/pci/vfio_pci_config.c | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
>> index 115a36f6f403..62023b4a373b 100644
>> --- a/drivers/vfio/pci/vfio_pci_config.c
>> +++ b/drivers/vfio/pci/vfio_pci_config.c
>> @@ -1180,8 +1180,10 @@ static int vfio_msi_cap_len(struct vfio_pci_device *vdev, u8 pos)
>>  		return -ENOMEM;
>>  
>>  	ret = init_pci_cap_msi_perm(vdev->msi_perm, len, flags);
>> -	if (ret)
>> +	if (ret) {
>> +		kfree(vdev->msi_perm);
>>  		return ret;
>> +	}
>>  
>>  	return len;
>>  }
>>
> 
> Doesn't vfio_config_free() take care of that in all cases?

Looks OK to me.
Reviewed-by: Eric Auger <eric.auger@redhat.com>

Looks vfio_config_free is called on vfio_pci_release whereas
vfio_msi_cap_len can fail in vfio_pci_open path.

Thanks

Eric
> 

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

* Re: [PATCH] vfio: fix potential memory leak in vfio_msi_cap_len
  2018-08-27 12:47 [PATCH] vfio: fix potential memory leak in vfio_msi_cap_len Li Qiang
  2018-08-30 14:15 ` David Hildenbrand
@ 2018-09-04 15:52 ` Alex Williamson
  1 sibling, 0 replies; 4+ messages in thread
From: Alex Williamson @ 2018-09-04 15:52 UTC (permalink / raw)
  To: Li Qiang; +Cc: eric.auger, kvm, linux-kernel, liqiang02

On Mon, 27 Aug 2018 05:47:21 -0700
Li Qiang <liq3ea@gmail.com> wrote:

> Free the vdev->msi_perm in error path.
> 
> Signed-off-by: Li Qiang <liq3ea@gmail.com>
> ---
>  drivers/vfio/pci/vfio_pci_config.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
> index 115a36f6f403..62023b4a373b 100644
> --- a/drivers/vfio/pci/vfio_pci_config.c
> +++ b/drivers/vfio/pci/vfio_pci_config.c
> @@ -1180,8 +1180,10 @@ static int vfio_msi_cap_len(struct vfio_pci_device *vdev, u8 pos)
>  		return -ENOMEM;
>  
>  	ret = init_pci_cap_msi_perm(vdev->msi_perm, len, flags);
> -	if (ret)
> +	if (ret) {
> +		kfree(vdev->msi_perm);
>  		return ret;
> +	}
>  
>  	return len;
>  }

Fix looks correct to me, I'll queue this for v4.20 with Eric's R-b.
Thanks,

Alex

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

end of thread, other threads:[~2018-09-04 15:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-27 12:47 [PATCH] vfio: fix potential memory leak in vfio_msi_cap_len Li Qiang
2018-08-30 14:15 ` David Hildenbrand
2018-09-03 17:00   ` Auger Eric
2018-09-04 15:52 ` Alex Williamson

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