[-next] scsi: iscsi: fix possible memory leak in iscsi_register_transport

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"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@xxxxxxxxxx>
---
 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);
-- 
2.17.1




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux