* [PATCH][Resend] SCSI, target, loopback: Fix memory leak in tcm_loop_make_scsi_hba()
@ 2011-06-27 21:54 Jesper Juhl
2011-06-27 22:25 ` Dan Carpenter
0 siblings, 1 reply; 5+ messages in thread
From: Jesper Juhl @ 2011-06-27 21:54 UTC (permalink / raw)
To: Nicholas A. Bellinger
Cc: James Bottomley, Dan Carpenter, Christoph Hellwig, linux-scsi,
linux-kernel
There is a memory leak in tcm_loop_make_scsi_hba().
If all the strstr() calls return NULL and we end up at
return ERR_PTR(-EINVAL);
then we'll be leaking the memory previously allocated to tl_hba as
that variable goes out of scope.
This patch should fix the leak.
Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
drivers/target/loopback/tcm_loop.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
Compile tested only.
Last submitted April 07, 2011
diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c
index 70c2e7f..aa3bb70 100644
--- a/drivers/target/loopback/tcm_loop.c
+++ b/drivers/target/loopback/tcm_loop.c
@@ -1321,7 +1321,8 @@ struct se_wwn *tcm_loop_make_scsi_hba(
printk(KERN_ERR "Unable to locate prefix for emulated Target Port:"
" %s\n", name);
- return ERR_PTR(-EINVAL);
+ ret = -EINVAL;
+ goto out;
check_len:
if (strlen(name) >= TL_WWN_ADDR_LEN) {
--
1.7.5.2
--
Jesper Juhl <jj@chaosbits.net> http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH][Resend] SCSI, target, loopback: Fix memory leak in tcm_loop_make_scsi_hba()
2011-06-27 21:54 [PATCH][Resend] SCSI, target, loopback: Fix memory leak in tcm_loop_make_scsi_hba() Jesper Juhl
@ 2011-06-27 22:25 ` Dan Carpenter
2011-06-27 22:30 ` Jesper Juhl
0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2011-06-27 22:25 UTC (permalink / raw)
To: Jesper Juhl
Cc: Nicholas A. Bellinger, James Bottomley, Christoph Hellwig,
linux-scsi, linux-kernel
On Mon, Jun 27, 2011 at 11:54:48PM +0200, Jesper Juhl wrote:
> --- a/drivers/target/loopback/tcm_loop.c
> +++ b/drivers/target/loopback/tcm_loop.c
> @@ -1321,7 +1321,8 @@ struct se_wwn *tcm_loop_make_scsi_hba(
>
> printk(KERN_ERR "Unable to locate prefix for emulated Target Port:"
> " %s\n", name);
> - return ERR_PTR(-EINVAL);
> + ret = -EINVAL;
> + goto out;
You've added a weird bunny hop goto here. It might be better to
change the if (ptr) check to if (!ptr) so we could fall through
here in the normal case.
>
> check_len:
> if (strlen(name) >= TL_WWN_ADDR_LEN) {
If this check fails then it calls kfree() and returns. It would be
cleaner to "goto out" here as well.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH][Resend] SCSI, target, loopback: Fix memory leak in tcm_loop_make_scsi_hba()
2011-06-27 22:25 ` Dan Carpenter
@ 2011-06-27 22:30 ` Jesper Juhl
2011-06-28 6:22 ` Dan Carpenter
0 siblings, 1 reply; 5+ messages in thread
From: Jesper Juhl @ 2011-06-27 22:30 UTC (permalink / raw)
To: Dan Carpenter
Cc: Nicholas A. Bellinger, James Bottomley, Christoph Hellwig,
linux-scsi, linux-kernel
On Tue, 28 Jun 2011, Dan Carpenter wrote:
> On Mon, Jun 27, 2011 at 11:54:48PM +0200, Jesper Juhl wrote:
> > --- a/drivers/target/loopback/tcm_loop.c
> > +++ b/drivers/target/loopback/tcm_loop.c
> > @@ -1321,7 +1321,8 @@ struct se_wwn *tcm_loop_make_scsi_hba(
> >
> > printk(KERN_ERR "Unable to locate prefix for emulated Target Port:"
> > " %s\n", name);
> > - return ERR_PTR(-EINVAL);
> > + ret = -EINVAL;
> > + goto out;
>
> You've added a weird bunny hop goto here. It might be better to
> change the if (ptr) check to if (!ptr) so we could fall through
> here in the normal case.
>
> >
> > check_len:
> > if (strlen(name) >= TL_WWN_ADDR_LEN) {
>
> If this check fails then it calls kfree() and returns. It would be
> cleaner to "goto out" here as well.
>
You mean like this - right?
---
There is a memory leak in tcm_loop_make_scsi_hba().
If all the strstr() calls return NULL and we end up at
return ERR_PTR(-EINVAL);
then we'll be leaking the memory previously allocated to tl_hba as
that variable goes out of scope.
This patch should fix the leak.
Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
drivers/target/loopback/tcm_loop.c | 17 ++++++++---------
1 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c
index 70c2e7f..e7a32e9 100644
--- a/drivers/target/loopback/tcm_loop.c
+++ b/drivers/target/loopback/tcm_loop.c
@@ -1314,22 +1314,21 @@ struct se_wwn *tcm_loop_make_scsi_hba(
goto check_len;
}
ptr = strstr(name, "iqn.");
- if (ptr) {
- tl_hba->tl_proto_id = SCSI_PROTOCOL_ISCSI;
- goto check_len;
+ if (!ptr) {
+ printk(KERN_ERR "Unable to locate prefix for emulated Target "
+ "Port: %s\n", name);
+ ret = -EINVAL;
+ goto out;
}
-
- printk(KERN_ERR "Unable to locate prefix for emulated Target Port:"
- " %s\n", name);
- return ERR_PTR(-EINVAL);
+ tl_hba->tl_proto_id = SCSI_PROTOCOL_ISCSI;
check_len:
if (strlen(name) >= TL_WWN_ADDR_LEN) {
printk(KERN_ERR "Emulated NAA %s Address: %s, exceeds"
" max: %d\n", name, tcm_loop_dump_proto_id(tl_hba),
TL_WWN_ADDR_LEN);
- kfree(tl_hba);
- return ERR_PTR(-EINVAL);
+ ret = -EINVAL;
+ goto out;
}
snprintf(&tl_hba->tl_wwn_address[0], TL_WWN_ADDR_LEN, "%s", &name[off]);
--
1.7.5.2
--
Jesper Juhl <jj@chaosbits.net> http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH][Resend] SCSI, target, loopback: Fix memory leak in tcm_loop_make_scsi_hba()
2011-06-27 22:30 ` Jesper Juhl
@ 2011-06-28 6:22 ` Dan Carpenter
2011-07-17 20:59 ` Nicholas A. Bellinger
0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2011-06-28 6:22 UTC (permalink / raw)
To: Jesper Juhl
Cc: Nicholas A. Bellinger, James Bottomley, Christoph Hellwig,
linux-scsi, linux-kernel
On Tue, Jun 28, 2011 at 12:30:17AM +0200, Jesper Juhl wrote:
>
> You mean like this - right?
Yeah.
Acked-by: Dan Carpenter <error27@gmail.com>
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH][Resend] SCSI, target, loopback: Fix memory leak in tcm_loop_make_scsi_hba()
2011-06-28 6:22 ` Dan Carpenter
@ 2011-07-17 20:59 ` Nicholas A. Bellinger
0 siblings, 0 replies; 5+ messages in thread
From: Nicholas A. Bellinger @ 2011-07-17 20:59 UTC (permalink / raw)
To: Dan Carpenter
Cc: Jesper Juhl, James Bottomley, Christoph Hellwig, linux-scsi,
linux-kernel, target-devel
On Tue, 2011-06-28 at 09:22 +0300, Dan Carpenter wrote:
> On Tue, Jun 28, 2011 at 12:30:17AM +0200, Jesper Juhl wrote:
> >
> > You mean like this - right?
>
> Yeah.
>
> Acked-by: Dan Carpenter <error27@gmail.com>
>
Hi Guys,
Following up on some items that where missed over my summer holiday.
Committed and pushed this patch into lio-core-2.6.git/master recently as
the following.
Thanks JesperJ and DanC!
--nab
--------------------------------------------------------------------
commit 90e104e39aa30437a8ac4572e4499e7c3a914458
Author: Jesper Juhl <jj@chaosbits.net>
Date: Tue Jun 28 00:30:17 2011 +0200
loopback: Fix memory leak in tcm_loop_make_scsi_hba()
There is a memory leak in tcm_loop_make_scsi_hba().
If all the strstr() calls return NULL and we end up at return ERR_PTR(-EINVAL);
then we'll be leaking the memory previously allocated to tl_hba as
that variable goes out of scope.
This patch should fix the leak.
Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Signed-off-by: Dan Carpenter <error27@gmail.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c
index 5075e9b..f603698 100644
--- a/drivers/target/loopback/tcm_loop.c
+++ b/drivers/target/loopback/tcm_loop.c
@@ -1288,22 +1288,21 @@ struct se_wwn *tcm_loop_make_scsi_hba(
goto check_len;
}
ptr = strstr(name, "iqn.");
- if (ptr) {
- tl_hba->tl_proto_id = SCSI_PROTOCOL_ISCSI;
- goto check_len;
+ if (!ptr) {
+ printk(KERN_ERR "Unable to locate prefix for emulated Target "
+ "Port: %s\n", name);
+ ret = -EINVAL;
+ goto out;
}
-
- printk(KERN_ERR "Unable to locate prefix for emulated Target Port:"
- " %s\n", name);
- return ERR_PTR(-EINVAL);
+ tl_hba->tl_proto_id = SCSI_PROTOCOL_ISCSI;
check_len:
if (strlen(name) >= TL_WWN_ADDR_LEN) {
printk(KERN_ERR "Emulated NAA %s Address: %s, exceeds"
" max: %d\n", name, tcm_loop_dump_proto_id(tl_hba),
TL_WWN_ADDR_LEN);
- kfree(tl_hba);
- return ERR_PTR(-EINVAL);
+ ret = -EINVAL;
+ goto out;
}
snprintf(&tl_hba->tl_wwn_address[0], TL_WWN_ADDR_LEN, "%s", &name[off]);
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-07-17 21:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-27 21:54 [PATCH][Resend] SCSI, target, loopback: Fix memory leak in tcm_loop_make_scsi_hba() Jesper Juhl
2011-06-27 22:25 ` Dan Carpenter
2011-06-27 22:30 ` Jesper Juhl
2011-06-28 6:22 ` Dan Carpenter
2011-07-17 20:59 ` Nicholas A. Bellinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®