From: Boaz Harrosh <bharrosh@panasas.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>,
Matthew Dharm <mdharm-usb@one-eyed-alien.net>,
Sven Schnelle <svens@stackframe.org>,
linux-kernel@vger.kernel.org,
linux-scsi <linux-scsi@vger.kernel.org>,
FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] [SCSI] gdth: Allocate sense_buffer to prevent NULL pointer dereference
Date: Tue, 11 Mar 2008 20:36:56 +0200 [thread overview]
Message-ID: <47D6D148.1090304@panasas.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0803111352450.21625-100000@iolanthe.rowland.org>
On Tue, Mar 11 2008 at 20:07 +0200, Alan Stern <stern@rowland.harvard.edu> wrote:
> On Tue, 11 Mar 2008, Boaz Harrosh wrote:
>
>> I would like to fix this better by calling scsi_get/put_command but there is
>> something fundamental that bothers me with isd200 driver. I can see that
>> an isd200_info struct is allocated and put on a struct us_data->extra. But
>> as I understand the code, the struct us_data is associated with a scsi_host
>> not a scsi_device. Are we guarantied that we have only one scsi_device
>> per host at all times?
>>
>> If not than the resources in isd200_info that are related to a request_queue
>> and are used from a .queuecommand code-path are not thread safe. (Like the
>> srb member)
>>
>> If Yes, then where in the code initialization sequence is the earliest place I
>> can get to a scsi_device. I could do that on first call to .queuecommand but
>> I would rather do it in a place that I could use GFP_KERNEL for allocation
>> of the extra command? (Same question on the tear down of the scsi_device)
>
> You can first get to the scsi_device in isd200_ata_command().
I was afraid of that. I don't think I want to call scsi_get_command
from within .queuecommand. I will leave the code hacked as today.
> The last
> place you can get to the scsi_device (if one exists!) is
> quiesce_and_remove_host() -- but that's part of the core, not specific
> to isd200.
>
Here two, it looks like I need to introduce a new function pointer for isd200
I'll leave it for now. Though I know this is not the last I'll see of this driver.
>> (And one more stupid question. Why does isd200_init_info allocates the info
>> structure but the isd200_free_info_ptrs does not free it, it kind of
>> limits the way it can be allocated, no?)
>
> Not at all. isd200_free_info_ptrs() frees everything pointed to by the
> info structure, and the info structure itself is freed later on by the
> usb-storage core in usb_stor_release_resources().
>
OK so in isd200_get_inquiry_data() at the end near the call to:
us->extra_destructor(info);
us->extra = NULL;
It leaks the info.
> If you wanted to free it in isd200_free_info_ptrs() you could; just
> make sure to set us->extra to NULL when you do, to avoid a double-free
> error.
>
Patch attached to fix the above fix
> Alan Stern
>
Please ACK the first patch sent, so James can put it in scsi-rc-fixes as part
of the sense_buffer effort for 2.6.25-rc
The below patch you can put threw the USB tree, it's for you.
---
From: Boaz Harrosh <bharrosh@panasas.com>
Date: Tue, 11 Mar 2008 20:30:53 +0200
Subject: [PATCH] isd200: Fix memory leak in isd200_get_inquiry_data
if the inquiry fails then the call to us->extra_destructor()
is assumed to also free the info structure. So make that
so in isd200_free_info_ptrs()
Signed-off-by: Boaz Harrosh <bharrosh@panasas.com>
---
drivers/usb/storage/isd200.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
index 9eb2cdf..77f4754 100644
--- a/drivers/usb/storage/isd200.c
+++ b/drivers/usb/storage/isd200.c
@@ -1471,6 +1471,9 @@ static void isd200_free_info_ptrs(void *info_)
kfree(info->id);
kfree(info->RegsBuf);
kfree(info->sense_buffer);
+ kfree(info);
+ us->extra = NULL;
+ us->extra_destructor = NULL;
}
}
--
1.5.3.3
next prev parent reply other threads:[~2008-03-11 18:38 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-09 12:41 [PATCH] [SCSI] gdth: Allocate sense_buffer to prevent NULL pointer dereference Sven Schnelle
2008-03-10 15:20 ` Boaz Harrosh
2008-03-10 21:12 ` James Bottomley
2008-03-10 21:50 ` Sven Schnelle
2008-03-11 15:47 ` Boaz Harrosh
2008-03-11 16:16 ` Boaz Harrosh
2008-03-11 17:39 ` Matthew Dharm
2008-03-11 18:07 ` Alan Stern
2008-03-11 18:07 ` Alan Stern
2008-03-11 18:36 ` Boaz Harrosh [this message]
2008-03-11 19:18 ` Alan Stern
2008-03-11 19:18 ` Alan Stern
2008-03-12 13:07 ` Boaz Harrosh
2008-03-12 13:11 ` [PATCH] isd200: Allocate sense_buffer for hacked up scsi_cmnd Boaz Harrosh
2008-03-12 15:10 ` Alan Stern
2008-03-12 15:10 ` Alan Stern
2008-03-12 15:24 ` [PATCH resend] " Boaz Harrosh
2008-03-12 16:54 ` James Bottomley
2008-03-12 17:05 ` Boaz Harrosh
2008-03-12 17:20 ` [PATCH ver3] " Boaz Harrosh
2008-03-13 20:01 ` Andrew Morton
2008-03-13 20:16 ` James Bottomley
2008-03-12 13:55 ` [PATCH] isd200: Fix memory leak in isd200_get_inquiry_data Boaz Harrosh
2008-03-12 15:11 ` Alan Stern
2008-03-12 15:11 ` Alan Stern
2008-03-12 15:08 ` [PATCH] [SCSI] gdth: Allocate sense_buffer to prevent NULL pointer dereference Alan Stern
2008-03-12 15:08 ` Alan Stern
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=47D6D148.1090304@panasas.com \
--to=bharrosh@panasas.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=akpm@linux-foundation.org \
--cc=fujita.tomonori@lab.ntt.co.jp \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mdharm-usb@one-eyed-alien.net \
--cc=stern@rowland.harvard.edu \
--cc=svens@stackframe.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.