Skip to contentSkip to conversation

bcache: fix use-after-free problem in bcache_device_free()

PATCH Applied Coly Li 3 participants 3 messages Nov 3, 2021

Subsystems (3)
lore
Share & tools
lore

Coly Li

author
#0 lore raw

PATCH 1/1 bcache: fix use-after-free problem in bcache_device_free()

In bcache_device_free(), pointer disk is referenced still in ida_simple_remove() after blk_cleanup_disk() gets called on this pointer. This may cause a potential panic by use-after-free on the disk pointer.

This patch fixes the problem by calling blk_cleanup_disk() after ida_simple_remove().

Fixes bc70852fd104 ("bcache: convert to blk_alloc_disk/blk_cleanup_disk")
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc [email protected] # v5.14+
---
 drivers/md/bcache/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/super.c +1 -1
index 4a9a65dff95e..86b9e355c583 100644
@@ -885,9 +885,9 @@ static void bcache_device_free(struct bcache_device *d)
 		bcache_device_detach(d);
 
 	if (disk) {
-		blk_cleanup_disk(disk);
 		ida_simple_remove(&bcache_device_idx,
 				  first_minor_to_idx(disk->first_minor));
+		blk_cleanup_disk(disk);
 	}
 
 	bioset_exit(&d->bio_split);
Signature · 1 line
2.31.1
maintainer Applied
#2 lore raw
In reply to Coly Li
Quoted 9 lines · Coly Li

In bcache_device_free(), pointer disk is referenced still in ida_simple_remove() after blk_cleanup_disk() gets called on this pointer. This may cause a potential panic by use-after-free on the disk pointer.

This patch fixes the problem by calling blk_cleanup_disk() after ida_simple_remove().

[...]

Applied, thanks!

[1/1] bcache: fix use-after-free problem in bcache_device_free()

      commit: 8468f45091d2866affed6f6a7aecc20779139173

Best regards,

Signature · 1 line
Jens Axboe