提交 10097449 编写于 作者: C Christoph Hellwig 提交者: Yang Yingliang

block: take bd_mutex around delete_partitions in del_gendisk

mainline inclusion
from mainline-v5.13-rc1
commit c76f48eb
category: bugfix
bugzilla: 55097
CVE: NA

--------------------------------

There is nothing preventing an ioctl from trying do delete partition
concurrenly with del_gendisk, so take open_mutex to serialize against
that.
Signed-off-by: NChristoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20210406062303.811835-6-hch@lst.deSigned-off-by: NJens Axboe <axboe@kernel.dk>
Conflicts:
	block/genhd.c
	block/partitions/core.c
[Yufen: linux-4.19 have not extract blk_drop_partitions().]
Signed-off-by: NYufen Yu <yuyufen@huawei.com>
Reviewed-by: NJason Yan <yanaijie@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 01f9b568
......@@ -747,6 +747,7 @@ void del_gendisk(struct gendisk *disk)
{
struct disk_part_iter piter;
struct hd_struct *part;
struct block_device *bdev;
blk_integrity_del(disk);
disk_del_events(disk);
......@@ -756,6 +757,14 @@ void del_gendisk(struct gendisk *disk)
* disk is marked as dead (GENHD_FL_UP cleared).
*/
down_write(&disk->lookup_sem);
/*
* If bdev is null, that menas memory allocate fail. Then
* add_partitions can also fail.
*/
bdev = bdget_disk(disk, 0);
if (bdev)
mutex_lock(&bdev->bd_mutex);
/* invalidate stuff */
disk_part_iter_init(&piter, disk,
DISK_PITER_INCL_EMPTY | DISK_PITER_REVERSE);
......@@ -765,6 +774,8 @@ void del_gendisk(struct gendisk *disk)
delete_partition(disk, part->partno);
}
disk_part_iter_exit(&piter);
if (bdev)
mutex_unlock(&bdev->bd_mutex);
invalidate_partition(disk, 0);
bdev_unhash_inode(disk_devt(disk));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册