kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vfio/mdev: Fix reference count leak in add_mdev_supported_type.
@ 2020-05-28  2:01 wu000273
  2020-05-28  7:02 ` Cornelia Huck
  2020-05-29 22:19 ` Alex Williamson
  0 siblings, 2 replies; 4+ messages in thread
From: wu000273 @ 2020-05-28  2:01 UTC (permalink / raw)
  To: kjlu
  Cc: wu000273, Kirti Wankhede, Alex Williamson, Cornelia Huck, Neo Jia,
	Dong Jia Shi, Jike Song, kvm, linux-kernel

From: Qiushi Wu <wu000273@umn.edu>

kobject_init_and_add() takes reference even when it fails.
If this function returns an error, kobject_put() must be called to
properly clean up the memory associated with the object. Thus,
replace kfree() by kobject_put() to fix this issue. Previous
commit "b8eb718348b8" fixed a similar problem.

Fixes: 7b96953bc640 ("vfio: Mediated device Core driver")
Signed-off-by: Qiushi Wu <wu000273@umn.edu>
---
 drivers/vfio/mdev/mdev_sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c
index 8ad14e5c02bf..917fd84c1c6f 100644
--- a/drivers/vfio/mdev/mdev_sysfs.c
+++ b/drivers/vfio/mdev/mdev_sysfs.c
@@ -110,7 +110,7 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent,
 				   "%s-%s", dev_driver_string(parent->dev),
 				   group->name);
 	if (ret) {
-		kfree(type);
+		kobject_put(&type->kobj);
 		return ERR_PTR(ret);
 	}
 
-- 
2.17.1


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

* Re: [PATCH] vfio/mdev: Fix reference count leak in add_mdev_supported_type.
  2020-05-28  2:01 [PATCH] vfio/mdev: Fix reference count leak in add_mdev_supported_type wu000273
@ 2020-05-28  7:02 ` Cornelia Huck
  2020-05-29 17:55   ` Kirti Wankhede
  2020-05-29 22:19 ` Alex Williamson
  1 sibling, 1 reply; 4+ messages in thread
From: Cornelia Huck @ 2020-05-28  7:02 UTC (permalink / raw)
  To: wu000273
  Cc: kjlu, Kirti Wankhede, Alex Williamson, Neo Jia, Dong Jia Shi,
	Jike Song, kvm, linux-kernel

On Wed, 27 May 2020 21:01:09 -0500
wu000273@umn.edu wrote:

> From: Qiushi Wu <wu000273@umn.edu>
> 
> kobject_init_and_add() takes reference even when it fails.
> If this function returns an error, kobject_put() must be called to
> properly clean up the memory associated with the object. Thus,
> replace kfree() by kobject_put() to fix this issue. Previous
> commit "b8eb718348b8" fixed a similar problem.
> 
> Fixes: 7b96953bc640 ("vfio: Mediated device Core driver")
> Signed-off-by: Qiushi Wu <wu000273@umn.edu>
> ---
>  drivers/vfio/mdev/mdev_sysfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Cornelia Huck <cohuck@redhat.com>


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

* Re: [PATCH] vfio/mdev: Fix reference count leak in add_mdev_supported_type.
  2020-05-28  7:02 ` Cornelia Huck
@ 2020-05-29 17:55   ` Kirti Wankhede
  0 siblings, 0 replies; 4+ messages in thread
From: Kirti Wankhede @ 2020-05-29 17:55 UTC (permalink / raw)
  To: Cornelia Huck, wu000273
  Cc: kjlu, Alex Williamson, Neo Jia, Dong Jia Shi, Jike Song, kvm,
	linux-kernel



On 5/28/2020 12:32 PM, Cornelia Huck wrote:
> On Wed, 27 May 2020 21:01:09 -0500
> wu000273@umn.edu wrote:
> 
>> From: Qiushi Wu <wu000273@umn.edu>
>>
>> kobject_init_and_add() takes reference even when it fails.
>> If this function returns an error, kobject_put() must be called to
>> properly clean up the memory associated with the object. Thus,
>> replace kfree() by kobject_put() to fix this issue. Previous
>> commit "b8eb718348b8" fixed a similar problem.
>>
>> Fixes: 7b96953bc640 ("vfio: Mediated device Core driver")
>> Signed-off-by: Qiushi Wu <wu000273@umn.edu>
>> ---
>>   drivers/vfio/mdev/mdev_sysfs.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
> 

Thanks for fixing.

Reviewed-by: Kirti Wankhede <kwankhede@nvidia.com>

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

* Re: [PATCH] vfio/mdev: Fix reference count leak in add_mdev_supported_type.
  2020-05-28  2:01 [PATCH] vfio/mdev: Fix reference count leak in add_mdev_supported_type wu000273
  2020-05-28  7:02 ` Cornelia Huck
@ 2020-05-29 22:19 ` Alex Williamson
  1 sibling, 0 replies; 4+ messages in thread
From: Alex Williamson @ 2020-05-29 22:19 UTC (permalink / raw)
  To: wu000273
  Cc: kjlu, Kirti Wankhede, Cornelia Huck, Neo Jia, Dong Jia Shi,
	Jike Song, kvm, linux-kernel

On Wed, 27 May 2020 21:01:09 -0500
wu000273@umn.edu wrote:

> From: Qiushi Wu <wu000273@umn.edu>
> 
> kobject_init_and_add() takes reference even when it fails.
> If this function returns an error, kobject_put() must be called to
> properly clean up the memory associated with the object. Thus,
> replace kfree() by kobject_put() to fix this issue. Previous
> commit "b8eb718348b8" fixed a similar problem.
> 
> Fixes: 7b96953bc640 ("vfio: Mediated device Core driver")
> Signed-off-by: Qiushi Wu <wu000273@umn.edu>
> ---

Applied to vfio next branch for v5.8 with Connie's and Kirti's reviews.
Thanks,

Alex

>  drivers/vfio/mdev/mdev_sysfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c
> index 8ad14e5c02bf..917fd84c1c6f 100644
> --- a/drivers/vfio/mdev/mdev_sysfs.c
> +++ b/drivers/vfio/mdev/mdev_sysfs.c
> @@ -110,7 +110,7 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent,
>  				   "%s-%s", dev_driver_string(parent->dev),
>  				   group->name);
>  	if (ret) {
> -		kfree(type);
> +		kobject_put(&type->kobj);
>  		return ERR_PTR(ret);
>  	}
>  


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

end of thread, other threads:[~2020-05-29 22:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-28  2:01 [PATCH] vfio/mdev: Fix reference count leak in add_mdev_supported_type wu000273
2020-05-28  7:02 ` Cornelia Huck
2020-05-29 17:55   ` Kirti Wankhede
2020-05-29 22:19 ` 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).