You need to sign in or sign up before continuing.
提交 375e23ab 编写于 作者: Y Yufen Yu 提交者: Yang Yingliang

block: avoid creating invalid symlink file for patitions

hulk inclusion
category: bugfix
bugzilla: 55097
CVE: NA

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

For now, there is no mechanism that can provent ioctl to call
add_partition after del_gendisk() have called delete_partition().
Then, invalid symlinks file may be created into /sys/class/block.

We try to fix this problem by setting GENHD_FL_UP early in del_gendisk()
and check the flag before adding partitions likely that do in
mainline kernel. Since all of them are cover by bdev->bd_mutex,
either add_partition success but will delete by del_gendisk(),
or add_partition will fail return as GENHD_FL_UP have been cleared.
Signed-off-by: NYufen Yu <yuyufen@huawei.com>
Reviewed-by: NJason Yan <yanaijie@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 10097449
...@@ -765,6 +765,7 @@ void del_gendisk(struct gendisk *disk) ...@@ -765,6 +765,7 @@ void del_gendisk(struct gendisk *disk)
bdev = bdget_disk(disk, 0); bdev = bdget_disk(disk, 0);
if (bdev) if (bdev)
mutex_lock(&bdev->bd_mutex); mutex_lock(&bdev->bd_mutex);
disk->flags &= ~GENHD_FL_UP;
/* 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);
...@@ -780,7 +781,6 @@ void del_gendisk(struct gendisk *disk) ...@@ -780,7 +781,6 @@ void del_gendisk(struct gendisk *disk)
invalidate_partition(disk, 0); invalidate_partition(disk, 0);
bdev_unhash_inode(disk_devt(disk)); bdev_unhash_inode(disk_devt(disk));
set_capacity(disk, 0); set_capacity(disk, 0);
disk->flags &= ~GENHD_FL_UP;
up_write(&disk->lookup_sem); up_write(&disk->lookup_sem);
if (!(disk->flags & GENHD_FL_HIDDEN)) if (!(disk->flags & GENHD_FL_HIDDEN))
......
...@@ -50,6 +50,10 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user ...@@ -50,6 +50,10 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
return -EINVAL; return -EINVAL;
mutex_lock(&bdev->bd_mutex); mutex_lock(&bdev->bd_mutex);
if (!(disk->flags & GENHD_FL_UP)) {
mutex_unlock(&bdev->bd_mutex);
return -ENXIO;
}
/* overlap? */ /* overlap? */
disk_part_iter_init(&piter, disk, disk_part_iter_init(&piter, disk,
......
...@@ -525,6 +525,9 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev) ...@@ -525,6 +525,9 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev)
struct parsed_partitions *state = NULL; struct parsed_partitions *state = NULL;
struct hd_struct *part; struct hd_struct *part;
int p, highest, res; int p, highest, res;
if (!(disk->flags & GENHD_FL_UP))
return -ENXIO;
rescan: rescan:
if (state && !IS_ERR(state)) { if (state && !IS_ERR(state)) {
free_partitions(state); free_partitions(state);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册