Skip to content

Commit

Permalink
[SCSI] bsg: fix oops on remove
Browse files Browse the repository at this point in the history
If you do a modremove of any sas driver, you run into an oops on
shutdown when the host is removed (coming from the host bsg device).
The root cause seems to be that there's a use after free of the
bsg_class_device:  In bsg_kref_release_function, this is used (to do a
put_device(bcg->parent) after bcg->release has been called.  In sas (and
possibly many other things) bcd->release frees the queue which contains
the bsg_class_device, so we get a put_device on unreferenced memory.
Fix this by taking a copy of the pointer to the parent before releasing
bsg.

Acked-by: FUJITA Tomonori <[email protected]>
Signed-off-by: James Bottomley <[email protected]>
  • Loading branch information
James Bottomley authored and James Bottomley committed Jul 12, 2008
1 parent 2789898 commit 8df5fc0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion block/bsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,11 +709,12 @@ static void bsg_kref_release_function(struct kref *kref)
{
struct bsg_class_device *bcd =
container_of(kref, struct bsg_class_device, ref);
struct device *parent = bcd->parent;

if (bcd->release)
bcd->release(bcd->parent);

put_device(bcd->parent);
put_device(parent);
}

static int bsg_put_device(struct bsg_device *bd)
Expand Down

0 comments on commit 8df5fc0

Please sign in to comment.