From: Bart Van Assche <bart.vanassche-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
To: Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: Sagi Grimberg
<sagig-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>,
Christoph Hellwig <hch-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
Sebastian Parschauer
<sebastian.riemer-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>,
"linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: [PATCH 1/6] IB/srp: Fix a memory leak
Date: Tue, 1 Dec 2015 10:17:32 -0800 [thread overview]
Message-ID: <565DE43C.6040805@sandisk.com> (raw)
In-Reply-To: <565DE3EC.2070002-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
If srp_connect_ch() returns a positive value then that is considered
by its caller as a connection failure but this does not result in a
scsi_host_put() call and additionally causes the srp_create_target()
function to return a positive value while it should return a negative
value. Avoid all this confusion and additionally fix a memory leak by
ensuring that srp_connect_ch() always returns a value that is <= 0.
This patch avoids that a rejected login triggers the following memory
leak:
unreferenced object 0xffff88021b24a220 (size 8):
comm "srp_daemon", pid 56421, jiffies 4295006762 (age 4240.750s)
hex dump (first 8 bytes):
68 6f 73 74 35 38 00 a5 host58..
backtrace:
[<ffffffff8151014a>] kmemleak_alloc+0x7a/0xc0
[<ffffffff81165c1e>] __kmalloc_track_caller+0xfe/0x160
[<ffffffff81260d2b>] kvasprintf+0x5b/0x90
[<ffffffff81260e2d>] kvasprintf_const+0x8d/0xb0
[<ffffffff81254b0c>] kobject_set_name_vargs+0x3c/0xa0
[<ffffffff81337e3c>] dev_set_name+0x3c/0x40
[<ffffffff81355757>] scsi_host_alloc+0x327/0x4b0
[<ffffffffa03edc8e>] srp_create_target+0x4e/0x8a0 [ib_srp]
[<ffffffff8133778b>] dev_attr_store+0x1b/0x20
[<ffffffff811f27fa>] sysfs_kf_write+0x4a/0x60
[<ffffffff811f1e8e>] kernfs_fop_write+0x14e/0x180
[<ffffffff81176eef>] __vfs_write+0x2f/0xf0
[<ffffffff811771e4>] vfs_write+0xa4/0x100
[<ffffffff81177c64>] SyS_write+0x54/0xc0
[<ffffffff8151b257>] entry_SYSCALL_64_fastpath+0x12/0x6f
Signed-off-by: Bart Van Assche <bart.vanassche-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
Reviewed-by: Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org>
Reviewed-by: Sagi Grimberg <sagig-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Cc: Sebastian Parschauer <sebastian.riemer-EIkl63zCoXaH+58JC4qpiA@public.gmane.org>
Cc: stable <stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
---
drivers/infiniband/ulp/srp/ib_srp.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index 9909022..a074dad 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -994,16 +994,16 @@ static int srp_connect_ch(struct srp_rdma_ch *ch, bool multich)
ret = srp_lookup_path(ch);
if (ret)
- return ret;
+ goto out;
while (1) {
init_completion(&ch->done);
ret = srp_send_req(ch, multich);
if (ret)
- return ret;
+ goto out;
ret = wait_for_completion_interruptible(&ch->done);
if (ret < 0)
- return ret;
+ goto out;
/*
* The CM event handling code will set status to
@@ -1011,15 +1011,16 @@ static int srp_connect_ch(struct srp_rdma_ch *ch, bool multich)
* back, or SRP_DLID_REDIRECT if we get a lid/qp
* redirect REJ back.
*/
- switch (ch->status) {
+ ret = ch->status;
+ switch (ret) {
case 0:
ch->connected = true;
- return 0;
+ goto out;
case SRP_PORT_REDIRECT:
ret = srp_lookup_path(ch);
if (ret)
- return ret;
+ goto out;
break;
case SRP_DLID_REDIRECT:
@@ -1028,13 +1029,16 @@ static int srp_connect_ch(struct srp_rdma_ch *ch, bool multich)
case SRP_STALE_CONN:
shost_printk(KERN_ERR, target->scsi_host, PFX
"giving up on stale connection\n");
- ch->status = -ECONNRESET;
- return ch->status;
+ ret = -ECONNRESET;
+ goto out;
default:
- return ch->status;
+ goto out;
}
}
+
+out:
+ return ret <= 0 ? ret : -ENODEV;
}
static int srp_inv_rkey(struct srp_rdma_ch *ch, u32 rkey)
--
2.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2015-12-01 18:17 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-01 18:16 [PATCH 0/6] SRP initiator related bug fixes Bart Van Assche
[not found] ` <565DE3EC.2070002-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-12-01 18:17 ` Bart Van Assche [this message]
2015-12-01 18:18 ` [PATCH 2/6] IB/srp: Fix possible send queue overflow Bart Van Assche
[not found] ` <565DE45B.7060100-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-12-02 12:34 ` Christoph Hellwig
2015-12-01 18:18 ` [PATCH 3/6] IB/srp: Initialize dma_length in srp_map_idb Bart Van Assche
[not found] ` <565DE476.3080308-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-12-01 18:35 ` Sagi Grimberg
2015-12-01 18:18 ` [PATCH 4/6] IB/srp: Fix indirect data buffer rkey endianness Bart Van Assche
[not found] ` <565DE487.2010803-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-12-01 18:37 ` Sagi Grimberg
[not found] ` <565DE8F7.5060100-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-12-01 18:46 ` Bart Van Assche
[not found] ` <565DEB13.6040508-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-12-02 9:32 ` Sagi Grimberg
2015-12-02 12:35 ` Christoph Hellwig
2015-12-01 18:19 ` [PATCH 5/6] IB core: Fix ib_sg_to_pages() Bart Van Assche
[not found] ` <565DE49D.4020102-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-12-01 18:32 ` Sagi Grimberg
[not found] ` <565DE7D0.4080408-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-12-01 19:10 ` Bart Van Assche
[not found] ` <565DF0A5.6040102-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-12-02 9:31 ` Sagi Grimberg
[not found] ` <565EBA78.3050201-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-12-03 2:22 ` Bart Van Assche
[not found] ` <565FA75E.7010100-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-12-03 9:07 ` Sagi Grimberg
2015-12-03 9:18 ` Christoph Hellwig
[not found] ` <20151203091806.GB21893-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2015-12-04 0:04 ` Bart Van Assche
[not found] ` <5660D881.7020801-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-12-06 10:37 ` Sagi Grimberg
2015-12-06 14:02 ` Christoph Hellwig
2015-12-01 18:19 ` [PATCH 6/6] IB/srp: Fix srp_map_sg_fr() Bart Van Assche
[not found] ` <565DE4BA.1040703-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-12-01 18:35 ` Sagi Grimberg
[not found] ` <565DE864.5050407-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-12-01 18:39 ` Bart Van Assche
[not found] ` <565DE977.2070606-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-12-02 11:59 ` Sagi Grimberg
[not found] ` <565EDD2A.6050407-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-12-02 12:41 ` Christoph Hellwig
[not found] ` <20151202124154.GF28278-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2015-12-02 12:50 ` Sagi Grimberg
[not found] ` <565EE90D.8060303-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-12-03 8:46 ` Sagi Grimberg
[not found] ` <56600152.5050401-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2015-12-03 9:11 ` Christoph Hellwig
2015-12-04 23:08 ` [PATCH 0/6] SRP initiator related bug fixes Bart Van Assche
[not found] ` <56621CDF.3070604-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-12-05 11:17 ` Christoph Hellwig
[not found] ` <20151205111715.GA31393-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2015-12-07 17:15 ` Bart Van Assche
2015-12-07 19:26 ` Bart Van Assche
[not found] ` <5665DD50.5090906-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2015-12-07 21:07 ` Doug Ledford
[not found] ` <5665F502.5020305-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-12-07 22:07 ` Bart Van Assche
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=565DE43C.6040805@sandisk.com \
--to=bart.vanassche-xdaiopvojttbdgjk7y7tuq@public.gmane.org \
--cc=dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=hch-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=sagig-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org \
--cc=sebastian.riemer-EIkl63zCoXaH+58JC4qpiA@public.gmane.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.