public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Mike Christie <michael.christie@oracle.com>
To: Zhou Guanghui <zhouguanghui1@huawei.com>,
	lduncan@suse.com, cleech@redhat.com, jejb@linux.ibm.com,
	martin.petersen@oracle.com
Cc: open-iscsi@googlegroups.com, linux-scsi@vger.kernel.org
Subject: Re: [-next] scsi: iscsi: fix possible memory leak in iscsi_register_transport
Date: Wed, 9 Nov 2022 12:40:11 -0600	[thread overview]
Message-ID: <c4b77a0f-c53d-42fa-8d42-a08a12f59667@oracle.com> (raw)
In-Reply-To: <20221109081917.34311-1-zhouguanghui1@huawei.com>

On 11/9/22 2:19 AM, Zhou Guanghui wrote:
> "unreferenced object 0xffff888117908420 (size 16):
>   comm ""modprobe"", pid 18125, jiffies 4319017437 (age 73.039s)
>   hex dump (first 16 bytes):
>     62 65 32 69 73 63 73 69 00 84 90 17 81 88 ff ff  be2iscsi........
>   backtrace:
>     [<00000000f78a13b3>] __kmem_cache_alloc_node+0x157/0x220
>     [<00000000200a51a4>] __kmalloc_node_track_caller+0x44/0x1b0
>     [<0000000033ea4d64>] kstrdup+0x3a/0x70
>     [<00000000ec6d2980>] kstrdup_const+0x41/0x60
>     [<0000000055015f6f>] kvasprintf_const+0xf5/0x180
>     [<000000009dd443d2>] kobject_set_name_vargs+0x56/0x150
>     [<00000000f3448e98>] dev_set_name+0xab/0xe0
>     [<0000000080ab8992>] iscsi_register_transport+0x1f8/0x610 [scsi_transport_iscsi]
>     [<000000005e2c324d>] 0xffffffffc1260012
>     [<00000000df6e6a36>] do_one_initcall+0xcb/0x4d0
>     [<00000000181109df>] do_init_module+0x1ca/0x5f0
>     [<00000000b3c4fec8>] load_module+0x6133/0x70f0
>     [<00000000feb08394>] __do_sys_finit_module+0x12f/0x1c0
>     [<00000000ca6af44d>] do_syscall_64+0x37/0x90
>     [<00000000132e1a8b>] entry_SYSCALL_64_after_hwframe+0x63/0xcd"
> 
> If device_register() returns error in iscsi_register_transport(),
> the name allocated by the dev_set_name() need be freed.
> 
> Fix this by calling put_device(), the name will be freed in the
> kobject_cleanup(), and the priv will be freed in
> iscsi_transport_release.
> 
> Signed-off-by: Zhou Guanghui <zhouguanghui1@huawei.com>
> ---
>  drivers/scsi/scsi_transport_iscsi.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
> index cd3db9684e52..51e2c0f5e2d0 100644
> --- a/drivers/scsi/scsi_transport_iscsi.c
> +++ b/drivers/scsi/scsi_transport_iscsi.c
> @@ -4815,7 +4815,7 @@ iscsi_register_transport(struct iscsi_transport *tt)
>  	dev_set_name(&priv->dev, "%s", tt->name);
>  	err = device_register(&priv->dev);
>  	if (err)
> -		goto free_priv;
> +		goto put_dev;
>  
>  	err = sysfs_create_group(&priv->dev.kobj, &iscsi_transport_group);
>  	if (err)
> @@ -4850,8 +4850,8 @@ iscsi_register_transport(struct iscsi_transport *tt)
>  unregister_dev:
>  	device_unregister(&priv->dev);
>  	return NULL;
> -free_priv:
> -	kfree(priv);
> +put_dev:
> +	put_device(&priv->dev);
>  	return NULL;
>  }
>  EXPORT_SYMBOL_GPL(iscsi_register_transport);

Reviewed-by: Mike Christie <michael.christie@oracle.com>

Shoot, I see the comment about using put_device in device_add.
I'm not sure what happened, but I made the same mistake above
in 4 other places.

Do you want to send patches for the other ones? If not, I'll do
it.


  reply	other threads:[~2022-11-09 19:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09  8:19 [-next] scsi: iscsi: fix possible memory leak in iscsi_register_transport Zhou Guanghui
2022-11-09 18:40 ` Mike Christie [this message]
2022-11-10  2:01   ` Zhouguanghui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c4b77a0f-c53d-42fa-8d42-a08a12f59667@oracle.com \
    --to=michael.christie@oracle.com \
    --cc=cleech@redhat.com \
    --cc=jejb@linux.ibm.com \
    --cc=lduncan@suse.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=open-iscsi@googlegroups.com \
    --cc=zhouguanghui1@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox