Linux-SCSI Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] scsi: Fix reference count leak in iscsi_boot_create_kobj.
@ 2020-05-28 20:13 wu000273
  2020-05-29 15:09 ` Lee Duncan
  2020-06-03  2:31 ` Martin K. Petersen
  0 siblings, 2 replies; 3+ messages in thread
From: wu000273 @ 2020-05-28 20:13 UTC (permalink / raw)
  To: kjlu
  Cc: wu000273, Lee Duncan, Chris Leech, James E.J. Bottomley,
	Martin K. Petersen, open-iscsi, linux-scsi, linux-kernel

From: Qiushi Wu <wu000273@umn.edu>

kobject_init_and_add() should be handled when it return an error,
because 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. Previous
commit "b8eb718348b8" fixed a similar problem. Thus replace calling
kfree() by calling kobject_put().

Signed-off-by: Qiushi Wu <wu000273@umn.edu>
---
 drivers/scsi/iscsi_boot_sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/iscsi_boot_sysfs.c b/drivers/scsi/iscsi_boot_sysfs.c
index e4857b728033..a64abe38db2d 100644
--- a/drivers/scsi/iscsi_boot_sysfs.c
+++ b/drivers/scsi/iscsi_boot_sysfs.c
@@ -352,7 +352,7 @@ iscsi_boot_create_kobj(struct iscsi_boot_kset *boot_kset,
 	boot_kobj->kobj.kset = boot_kset->kset;
 	if (kobject_init_and_add(&boot_kobj->kobj, &iscsi_boot_ktype,
 				 NULL, name, index)) {
-		kfree(boot_kobj);
+		kobject_put(&boot_kobj->kobj);
 		return NULL;
 	}
 	boot_kobj->data = data;
-- 
2.17.1


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

* Re: [PATCH] scsi: Fix reference count leak in iscsi_boot_create_kobj.
  2020-05-28 20:13 [PATCH] scsi: Fix reference count leak in iscsi_boot_create_kobj wu000273
@ 2020-05-29 15:09 ` Lee Duncan
  2020-06-03  2:31 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Lee Duncan @ 2020-05-29 15:09 UTC (permalink / raw)
  To: wu000273, kjlu
  Cc: Chris Leech, James E.J. Bottomley, Martin K. Petersen,
	open-iscsi, linux-scsi, linux-kernel

On 5/28/20 1:13 PM, wu000273@umn.edu wrote:
> From: Qiushi Wu <wu000273@umn.edu>
> 
> kobject_init_and_add() should be handled when it return an error,
> because 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. Previous
> commit "b8eb718348b8" fixed a similar problem. Thus replace calling
> kfree() by calling kobject_put().
> 
> Signed-off-by: Qiushi Wu <wu000273@umn.edu>
> ---
>  drivers/scsi/iscsi_boot_sysfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/iscsi_boot_sysfs.c b/drivers/scsi/iscsi_boot_sysfs.c
> index e4857b728033..a64abe38db2d 100644
> --- a/drivers/scsi/iscsi_boot_sysfs.c
> +++ b/drivers/scsi/iscsi_boot_sysfs.c
> @@ -352,7 +352,7 @@ iscsi_boot_create_kobj(struct iscsi_boot_kset *boot_kset,
>  	boot_kobj->kobj.kset = boot_kset->kset;
>  	if (kobject_init_and_add(&boot_kobj->kobj, &iscsi_boot_ktype,
>  				 NULL, name, index)) {
> -		kfree(boot_kobj);
> +		kobject_put(&boot_kobj->kobj);
>  		return NULL;
>  	}
>  	boot_kobj->data = data;
> 

Reviewed-by: Lee Duncan <lduncan@suse.com>

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

* Re: [PATCH] scsi: Fix reference count leak in iscsi_boot_create_kobj.
  2020-05-28 20:13 [PATCH] scsi: Fix reference count leak in iscsi_boot_create_kobj wu000273
  2020-05-29 15:09 ` Lee Duncan
@ 2020-06-03  2:31 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2020-06-03  2:31 UTC (permalink / raw)
  To: kjlu, wu000273
  Cc: Martin K . Petersen, Lee Duncan, open-iscsi,
	James E.J. Bottomley, linux-scsi, Chris Leech, linux-kernel

On Thu, 28 May 2020 15:13:53 -0500, wu000273@umn.edu wrote:

> kobject_init_and_add() should be handled when it return an error,
> because 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. Previous
> commit "b8eb718348b8" fixed a similar problem. Thus replace calling
> kfree() by calling kobject_put().

Applied to 5.8/scsi-queue, thanks!

[1/1] scsi: iscsi: Fix reference count leak in iscsi_boot_create_kobj
      https://git.kernel.org/mkp/scsi/c/0267ffce562c

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-28 20:13 [PATCH] scsi: Fix reference count leak in iscsi_boot_create_kobj wu000273
2020-05-29 15:09 ` Lee Duncan
2020-06-03  2:31 ` Martin K. Petersen

Linux-SCSI Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-scsi/0 linux-scsi/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-scsi linux-scsi/ https://lore.kernel.org/linux-scsi \
		linux-scsi@vger.kernel.org
	public-inbox-index linux-scsi

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-scsi


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git