Skip to content

Commit d6a3009

Browse files
Coly Ligregkh
authored andcommitted
bcache: fix use-after-free problem in bcache_device_free()
commit 8468f45 upstream. 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: bc70852 ("bcache: convert to blk_alloc_disk/blk_cleanup_disk") Signed-off-by: Coly Li <colyli@suse.de> Cc: Christoph Hellwig <hch@lst.de> Cc: Hannes Reinecke <hare@suse.de> Cc: Ulf Hansson <ulf.hansson@linaro.org> Cc: stable@vger.kernel.org # v5.14+ Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20211103064917.67383-1-colyli@suse.de Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a958d14 commit d6a3009

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/md/bcache/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,9 +885,9 @@ static void bcache_device_free(struct bcache_device *d)
885885
bcache_device_detach(d);
886886

887887
if (disk) {
888-
blk_cleanup_disk(disk);
889888
ida_simple_remove(&bcache_device_idx,
890889
first_minor_to_idx(disk->first_minor));
890+
blk_cleanup_disk(disk);
891891
}
892892

893893
bioset_exit(&d->bio_split);

0 commit comments

Comments
 (0)