Skip to content

Commit 9400775

Browse files
committed
Avoid dereferencing a 'request_queue' after last close.
On the last close of an 'md' device which as been stopped, the device is destroyed and in particular the request_queue is freed. The free is done in a separate thread so it might happen a short time later. __blkdev_put calls bdev_inode_switch_bdi *after* ->release has been called. Since commit f758eea bdev_inode_switch_bdi will dereference the 'old' bdi, which lives inside a request_queue, to get a spin lock. This causes the last close on an md device to sometime take a spin_lock which lives in freed memory - which results in an oops. So move the called to bdev_inode_switch_bdi before the call to ->release. Cc: Christoph Hellwig <hch@lst.de> Cc: Hugh Dickins <hughd@google.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Wu Fengguang <fengguang.wu@intel.com> Acked-by: Wu Fengguang <fengguang.wu@intel.com> Cc: stable@kernel.org Signed-off-by: NeilBrown <neilb@suse.de>
1 parent 43220aa commit 9400775

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎fs/block_dev.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,11 @@ static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part)
14291429
WARN_ON_ONCE(bdev->bd_holders);
14301430
sync_blockdev(bdev);
14311431
kill_bdev(bdev);
1432+
/* ->release can cause the old bdi to disappear,
1433+
* so must switch it out first
1434+
*/
1435+
bdev_inode_switch_bdi(bdev->bd_inode,
1436+
&default_backing_dev_info);
14321437
}
14331438
if (bdev->bd_contains == bdev) {
14341439
if (disk->fops->release)
@@ -1442,8 +1447,6 @@ static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part)
14421447
disk_put_part(bdev->bd_part);
14431448
bdev->bd_part = NULL;
14441449
bdev->bd_disk = NULL;
1445-
bdev_inode_switch_bdi(bdev->bd_inode,
1446-
&default_backing_dev_info);
14471450
if (bdev != bdev->bd_contains)
14481451
victim = bdev->bd_contains;
14491452
bdev->bd_contains = NULL;

0 commit comments

Comments
 (0)