Skip to contentSkip to conversation

use after free bug in __blkdev_get

PATCH In review Neil Brown 3 participants 3 messages Oct 26, 2009 VFS

lore
Share & tools
lore

Neil Brown

author
#0 lore raw

PATCH 1/1 use after free bug in __blkdev_get

commit 0762b8bde9729f10f8e6249809660ff2ec3ad735
(from 14 months ago) introduced a use-after-free bug which has just recently started manifesting in my md testing.
I tried git bisect to find out what caused the bug to start manifesting, and it could have been the recent change to blk_unregister_queue (48c0d4d4c04) but the results were inconclusive.

This patch certainly fixes my symptoms and looks correct as the two calls are now in the same order as elsewhere in that function.

fs/block_dev.c +1 -1
index 9cf4b92..8bed055 100644
@@ -1248,8 +1248,8 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
 			bd_set_size(bdev, (loff_t)bdev->bd_part->nr_sects << 9);
 		}
 	} else {
-		put_disk(disk);
 		module_put(disk->fops->owner);
+		put_disk(disk);
 		disk = NULL;
 		if (bdev->bd_contains == bdev) {
 			if (bdev->bd_disk->fops->open) {
#1 lore raw
Quoted 19 lines · Neil Brown

commit 0762b8bde9729f10f8e6249809660ff2ec3ad735
(from 14 months ago) introduced a use-after-free bug which has just recently started manifesting in my md testing.
I tried git bisect to find out what caused the bug to start manifesting, and it could have been the recent change to blk_unregister_queue (48c0d4d4c04) but the results were inconclusive.

This patch certainly fixes my symptoms and looks correct as the two calls are now in the same order as elsewhere in that function.

fs/block_dev.c +0 -0
index 9cf4b92..8bed055 100644

fs/block_dev.c static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) · line 1255

Quoted 9 lines
fs/block_dev.c +1 -1
@@ -1248,8 +1248,8 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
 			bd_set_size(bdev, (loff_t)bdev->bd_part->nr_sects << 9);
 		}
 	} else {
-		put_disk(disk);
 		module_put(disk->fops->owner);
+		put_disk(disk);
 		disk = NULL;
 		if (bdev->bd_contains == bdev) {
 			if (bdev->bd_disk->fops->open) {

Thanks Neil, good catch! Applied.

Signature · 1 line
Jens Axboe
Acked-by
#2 lore raw
Quoted 9 lines · Jens Axboe
Quoted 8 lines · Neil Brown

commit 0762b8bde9729f10f8e6249809660ff2ec3ad735
(from 14 months ago) introduced a use-after-free bug which has just recently started manifesting in my md testing.
I tried git bisect to find out what caused the bug to start manifesting, and it could have been the recent change to blk_unregister_queue (48c0d4d4c04) but the results were inconclusive.

Quoted 4 lines
Quoted 4 lines

This patch certainly fixes my symptoms and looks correct as the two calls are now in the same order as elsewhere in that function.

Oops, thanks for catching it.

Signature · 1 line
tejun