From: Mike Anderson <andmike@us.ibm.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: James Bottomley <James.Bottomley@steeleye.com>,
Andrew Morton <akpm@osdl.org>,
greg@kroah.com, Jens Axboe <axboe@suse.de>,
linux-usb-devel@lists.sourceforge.net,
SCSI Mailing List <linux-scsi@vger.kernel.org>
Subject: Re: bug 2400
Date: Mon, 5 Apr 2004 07:59:33 -0700 [thread overview]
Message-ID: <20040405145933.GC8535@us.ibm.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0404042235420.23916-100000@netrider.rowland.org>
PS, I am traveling today so future comments will be delayed a bit.
Alan Stern [stern@rowland.harvard.edu] wrote:
> All right, let's look at sd.c. I'll show you that _it_ doesn't obey the
> object lifetime rules. In sd_open we see this code (lightly edited):
>
>
> static int sd_open(struct inode *inode, struct file *filp)
> {
> struct gendisk *disk = inode->i_bdev->bd_disk;
> struct scsi_disk *sdkp = scsi_disk(disk);
> struct scsi_device *sdev;
> int retval;
>
> retval = scsi_disk_get(sdkp);
> if (retval)
> return retval;
>
> sdev = sdkp->device;
>
>
> As it turns out, the block layer guarantees that when sd_open runs the
> bd_disk pointer will be valid. It does this by following the pattern I
> mentioned in an earlier message -- drivers/base/map.c uses a
> subsystem-wide semaphore, domain_sem, to properly synchronize lookups and
> deletes.
>
> Next, the scsi_disk inline function returns:
>
> container_of(disk->private_data, struct scsi_disk, driver);
>
> How do you know that the scsi_disk pointed to by disk->private_data still
> exists? So far as I can see, the gendisk doesn't take any references to
> it. Correct me if I'm wrong, but there doesn't seem to be anything
> preventing a disconnect event from arriving after the open() call has got
> a valid reference to the gendisk, and succeeding in deallocating the
> scsi_disk before this code executes. There's only one reference between
> the scsi_disk and the gendisk, and it goes the wrong way: the scsi_disk
> owns a reference to the gendisk.
>
> But let's suppose that works okay, so sdkp is a valid pointer. Then
> the code calls scsi_disk_get(), which in turn calls scsi_device_get() for
> sdkp->device. How do you know that this doesn't point to deallocated
> storage? The only reference to the scsi_device is taken (in a rather
> convoluted way) by the gendisk, and it is dropped during del_gendisk() --
> not when the gendisk is released. Hence it is entirely possible for a
> disconnect event to have freed the scsi_device when this code executes.
>
>
> There's two potential oopses for you. I don't have a full grasp of the
> web of interlocking references (and interlocking code) in the SCSI,
> gendisk, and block layers, but it seems likely that at least one of
> these might actually happen.
>
> The object lifetime rules require that in your disconnect() routine, you
> must tell all your users that your structure is going away, but you must
> not free the structure until your users have notified you that they won't
> try to use it any more. When the scsi_disk is on its way out, sd.c tells
> the gendisk but doesn't wait for a notification in return. When the
> scsi_device is on its way out the SCSI core tells sd.c, but sd.c doesn't
> send back its notification at the right time.
As I previously stated there is no notification back from the block
layer that users are complete with a structure. Currently the only
method to prevent an oops looks like sd_remove would need to use
lock_kernel so that scsi could ensure that a user would be through open
which means the sd_remove would not take references to zero or the user
has not made it far enough through do open that they have received a
gendisk structure so that del_gendisk will ensure they do not call
sd_open.
I would like another method, but this looks like it would need to be
another shared sync mechanism between scsi layer (an other blk
interfaces) and block layer or a lookup method similar to kobj_lookup
in scsi open routines so that a object can be unmapped atomically.
-andmike
--
Michael Anderson
andmike@us.ibm.com
next prev parent reply other threads:[~2004-04-07 1:12 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-01 21:15 bug 2400 Andrew Morton
2004-04-01 21:52 ` Matt Gulick
2004-04-01 22:08 ` Andrew Morton
2004-04-01 22:48 ` Matt Gulick
2004-04-01 22:40 ` James Bottomley
2004-04-01 22:53 ` Matt Gulick
2004-04-01 23:07 ` Matthew Dharm
2004-04-01 23:32 ` James Bottomley
2004-04-02 0:29 ` Steven Dake
2004-04-02 8:43 ` Mike Anderson
2004-04-02 15:57 ` James Bottomley
2004-04-02 16:45 ` Mike Anderson
2004-04-02 17:05 ` James Bottomley
2004-04-02 17:44 ` Mike Anderson
2004-04-02 18:13 ` James Bottomley
2004-04-02 23:40 ` Mike Anderson
2004-04-03 0:25 ` James Bottomley
2004-04-04 1:40 ` Alan Stern
2004-04-04 15:23 ` James Bottomley
2004-04-04 16:46 ` Alan Stern
2004-04-04 17:04 ` James Bottomley
2004-04-05 3:17 ` Alan Stern
2004-04-05 14:59 ` Mike Anderson [this message]
2004-04-05 21:27 ` James Bottomley
2004-04-06 14:00 ` Alan Stern
2004-04-05 22:10 ` Patrick Mansfield
2004-04-06 14:10 ` Alan Stern
2004-04-08 14:09 ` Alan Stern
2004-04-08 16:24 ` Matt Gulick
2004-04-08 18:33 ` Alan Stern
2004-04-08 19:44 ` Matt Gulick
2004-04-05 13:30 ` [linux-usb-devel] " Oliver Neukum
2004-04-04 18:16 ` David Brownell
2004-04-04 18:42 ` James Bottomley
2004-04-05 3:54 ` David Brownell
2004-04-05 21:44 ` James Bottomley
2004-04-05 23:23 ` [linux-usb-devel] " David Brownell
2004-04-06 1:19 ` James Bottomley
2004-04-06 6:52 ` Oliver Neukum
2004-04-06 14:03 ` James Bottomley
2004-04-07 9:19 ` Oliver.Neukum
2004-04-06 15:10 ` David Brownell
2004-04-06 15:47 ` James Bottomley
2004-04-06 16:16 ` David Brownell
2004-04-06 16:55 ` Alan Stern
2004-04-06 17:13 ` James Bottomley
2004-04-02 23:36 ` James Bottomley
2004-04-03 0:11 ` Mike Anderson
2004-04-03 0:16 ` James Bottomley
2004-04-05 4:33 ` Patrick Mansfield
2004-04-05 14:09 ` James Bottomley
2004-04-05 21:07 ` James Bottomley
2004-04-06 9:22 ` Jens Axboe
2004-04-06 13:56 ` James Bottomley
2004-04-06 14:04 ` Jens Axboe
2004-04-06 14:09 ` James Bottomley
2004-04-08 23:06 ` Greg KH
2004-04-09 11:28 ` James Bottomley
2004-04-05 14:03 ` Jens Axboe
2004-04-05 21:08 ` James Bottomley
2004-04-06 9:22 ` Jens Axboe
-- strict thread matches above, loose matches on Subject: below --
2004-04-06 15:09 Heiko Carstens
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=20040405145933.GC8535@us.ibm.com \
--to=andmike@us.ibm.com \
--cc=James.Bottomley@steeleye.com \
--cc=akpm@osdl.org \
--cc=axboe@suse.de \
--cc=greg@kroah.com \
--cc=linux-scsi@vger.kernel.org \
--cc=linux-usb-devel@lists.sourceforge.net \
--cc=stern@rowland.harvard.edu \
/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