提交 956ae9cd 编写于 作者: C Christoph Hellwig 提交者: Zheng Zengkai

block: take bd_mutex around delete_partitions in del_gendisk

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

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c76f48eb5c084b1e15c931ae8cc1826cd771d70d

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

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>
Conflict:
	block/genhd.c
	block/partitions/core.c
[yufen: del_gendisk didn't call blk_drop_partitions().]
Signed-off-by: NYufen Yu <yuyufen@huawei.com>
Reviewed-by: NJason Yan <yanaijie@huawei.com>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 ecb923f0
...@@ -901,6 +901,7 @@ void del_gendisk(struct gendisk *disk) ...@@ -901,6 +901,7 @@ void del_gendisk(struct gendisk *disk)
{ {
struct disk_part_iter piter; struct disk_part_iter piter;
struct hd_struct *part; struct hd_struct *part;
struct block_device *bdev;
might_sleep(); might_sleep();
...@@ -912,6 +913,13 @@ void del_gendisk(struct gendisk *disk) ...@@ -912,6 +913,13 @@ void del_gendisk(struct gendisk *disk)
* disk is marked as dead (GENHD_FL_UP cleared). * disk is marked as dead (GENHD_FL_UP cleared).
*/ */
down_write(&disk->lookup_sem); down_write(&disk->lookup_sem);
/*
* If bdev is null, that means memory allocate fail. Then
* add_partitions can also fail.
*/
bdev = bdget_disk(disk, 0);
if (bdev)
mutex_lock(&bdev->bd_mutex);
/* invalidate stuff */ /* invalidate stuff */
disk_part_iter_init(&piter, disk, disk_part_iter_init(&piter, disk,
DISK_PITER_INCL_EMPTY | DISK_PITER_REVERSE); DISK_PITER_INCL_EMPTY | DISK_PITER_REVERSE);
...@@ -920,6 +928,10 @@ void del_gendisk(struct gendisk *disk) ...@@ -920,6 +928,10 @@ void del_gendisk(struct gendisk *disk)
delete_partition(part); delete_partition(part);
} }
disk_part_iter_exit(&piter); disk_part_iter_exit(&piter);
if (bdev) {
mutex_unlock(&bdev->bd_mutex);
bdput(bdev);
}
invalidate_partition(disk, 0); invalidate_partition(disk, 0);
set_capacity(disk, 0); set_capacity(disk, 0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册