mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Jens Axboe <jaxboe@fusionio.com>
Cc: linux-kernel@vger.kernel.org, kay.sievers@vrfy.org, hch@infradead.org
Subject: block: Fix oops caused by __blkdev_get() calling disk_unblock_events() with invalid @disk
Date: Wed, 9 Mar 2011 16:38:59 +0100	[thread overview]
Message-ID: <20110309153859.GD27010@htj.dyndns.org> (raw)
In-Reply-To: <4D779396.7050905@fusionio.com>

Commit 57c966b8b2 (block: Don't check events while open is in
progress) made __blkdev_get() block events around open calls; however,
it used invalid @disk pointer in the following cases.

* When ->open() returns -ERESTARTSYS, disk_unblock_events() is called
  after @disk is put.  @disk may be invalid by the time unblock is
  called.

  This is fixed by moving references after disk_unblock_events().

* When there are multiple openers, @disk is cleared to %NULL and later
  disk_unblock_disk() is called with %NULL @disk causing oops.

  This is fixed by moving reference putting after open success is
  determined and not clearing @disk to %NULL.  On success, @disk is
  valid because there is another opener holding reference to it.  On
  failure, the references are put after disk_unblock_events() is
  called.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Jens Axboe <axboe@kernel.dk>
---
Ah, sorry about that.  My test setup didn't include a device with
multiple partitions on it so the more than one opener case never
triggered.

Thanks.

 fs/block_dev.c |   13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

Index: work/fs/block_dev.c
===================================================================
--- work.orig/fs/block_dev.c
+++ work/fs/block_dev.c
@@ -1109,11 +1109,11 @@ static int __blkdev_get(struct block_dev
 					 */
 					disk_put_part(bdev->bd_part);
 					bdev->bd_part = NULL;
-					module_put(disk->fops->owner);
-					put_disk(disk);
 					bdev->bd_disk = NULL;
 					mutex_unlock(&bdev->bd_mutex);
 					disk_unblock_events(disk);
+					module_put(disk->fops->owner);
+					put_disk(disk);
 					goto restart;
 				}
 				if (ret)
@@ -1150,9 +1150,6 @@ static int __blkdev_get(struct block_dev
 			bd_set_size(bdev, (loff_t)bdev->bd_part->nr_sects << 9);
 		}
 	} else {
-		module_put(disk->fops->owner);
-		put_disk(disk);
-		disk = NULL;
 		if (bdev->bd_contains == bdev) {
 			if (bdev->bd_disk->fops->open) {
 				ret = bdev->bd_disk->fops->open(bdev, mode);
@@ -1162,6 +1159,9 @@ static int __blkdev_get(struct block_dev
 			if (bdev->bd_invalidated)
 				rescan_partitions(bdev->bd_disk, bdev);
 		}
+		/* only one opener holds refs to the module and disk */
+		module_put(disk->fops->owner);
+		put_disk(disk);
 	}
 	bdev->bd_openers++;
 	if (for_part)
@@ -1182,8 +1182,7 @@ static int __blkdev_get(struct block_dev
 	mutex_unlock(&bdev->bd_mutex);
 	disk_unblock_events(disk);
  out:
-	if (disk)
-		module_put(disk->fops->owner);
+	module_put(disk->fops->owner);
 	put_disk(disk);
 	bdput(bdev);
 

  reply	other threads:[~2011-03-09 15:41 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-09  9:13 [PATCHSET] block: Convert block drivers to ->check_events(), take#2 Tejun Heo
2011-03-09  9:13 ` [PATCH 01/16] block: Don't implicitly trigger event check on disk_unblock_events() Tejun Heo
2011-03-09  9:13 ` [PATCH 02/16] block: Don't check events on close unless it was blocked Tejun Heo
2011-03-09  9:13 ` [PATCH 03/16] block: Don't check events while open is in progress Tejun Heo
2011-03-09  9:13 ` [PATCH 04/16] ide: Convert to bdops->check_events() Tejun Heo
2011-03-09 22:17   ` David Miller
2011-03-09  9:13 ` [PATCH 05/16] floppy,{ami|ata}flop: " Tejun Heo
2011-03-09  9:13 ` [PATCH 06/16] gdrom,viocd: " Tejun Heo
2011-03-09  9:13 ` [PATCH 07/16] paride: " Tejun Heo
2011-03-09  9:13 ` [PATCH 08/16] dac960: " Tejun Heo
2011-03-09  9:13 ` [PATCH 09/16] swim[3]: " Tejun Heo
2011-03-10  0:10   ` Benjamin Herrenschmidt
2011-03-09  9:13 ` [PATCH 10/16] ub: " Tejun Heo
2011-03-09 16:46   ` Pete Zaitcev
2011-03-09 16:58     ` Tejun Heo
2011-03-09  9:13 ` [PATCH 11/16] xsysace: " Tejun Heo
2011-03-09  9:13 ` [PATCH 12/16] i2o_block: " Tejun Heo
2011-03-09  9:13 ` [PATCH 13/16] s390/tape_block: " Tejun Heo
2011-03-09  9:13 ` [PATCH 14/16] umem: Drop dummy ->media_changed() Tejun Heo
2011-03-09  9:13 ` [PATCH 15/16] pktcdvd: Convert to bdops->check_events() Tejun Heo
2011-03-09  9:13 ` [PATCH 16/16] staging: " Tejun Heo
2011-03-09  9:20 ` [PATCHSET] block: Convert block drivers to ->check_events(), take#2 Jens Axboe
2011-03-09 14:49   ` Jens Axboe
2011-03-09 15:38     ` Tejun Heo [this message]
2011-03-09 18:26       ` block: Fix oops caused by __blkdev_get() calling disk_unblock_events() with invalid @disk Jens Axboe
2011-03-09 18:59         ` Tejun Heo
2011-03-09 19:16           ` Jens Axboe

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=20110309153859.GD27010@htj.dyndns.org \
    --to=tj@kernel.org \
    --cc=hch@infradead.org \
    --cc=jaxboe@fusionio.com \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome