block: not create too many partitions
PATCH v2 1/1 block: not create too many partitions
Commit a33df75c6328 ("block: use an xarray for disk->part_tbl") drops check on max supported partitions number, and allows partition with bigger partition number to be added. However, ->bd_partno is defined as u8, so partition index of xarray table may not match with ->bd_partno. Then delete_partition() may delete one unmatched partition, and caused use-after-free.
---
V2:
- don't check disk_max_parts() which is supposed to not zero
block/partitions/core.c | 7 +++++++ 1 file changed, 7 insertions(+)
block/partitions/core.c +7 -0
@@ -322,6 +322,13 @@ static struct block_device *add_partition(struct gendisk *disk, int partno,const char *dname;int err; +/* +* disk_max_parts() won't be zero, either GENHD_FL_EXT_DEVT is set +* or 'minors' is passed to alloc_disk(). +*/ +if (partno >=disk_max_parts (disk)) +return ERR_PTR (-EINVAL ); +/* * Partitions are not supported on zoned block devices that are used as * such.
Signature · 1 line
2.29.2
Quoted 6 lines · Ming Lei
Commit
a33df75c6328("block: use an xarray fordisk->part_tbl") drops check on max supported partitions number, and allows partition with bigger partition number to be added. However, ->bd_partno is defined as u8, so partition index of xarray table may not match with ->bd_partno. Thendelete_partition()may delete one unmatched partition, and caused use-after-free.
Applied, thanks for nailing this one down, Ming.
Signature · 1 line
Jens Axboe
Quoted 27 lines · Ming Lei
Commit
a33df75c6328("block: use an xarray fordisk->part_tbl") drops check on max supported partitions number, and allows partition with bigger partition number to be added. However, ->bd_partno is defined as u8, so partition index of xarray table may not match with ->bd_partno. Thendelete_partition()may delete one unmatched partition, and caused use-after-free.Cc Bart Van Assche <[email protected]>Reported-by [email protected]Fixes a33df75c6328 ("block: use an xarray for disk->part_tbl")Signed-off-by Ming Lei <[email protected]>---
V2:
- don't checkdisk_max_parts()which is supposed to not zeroblock/partitions/core.c | 7 +++++++ 1 file changed, 7 insertions(+)block/partitions/core.c +0
-0@@ -322,6 +322,13 @@ static struct block_device *add_partition(struct gendisk *disk, int partno,const char *dname;int err;
block/partitions/core.c static struct block_device *add_partition(struct gendisk *disk, int partno, · line 334
Quoted 10 lines
block/partitions/core.c +7
-0+/* +* disk_max_parts() won't be zero, either GENHD_FL_EXT_DEVT is set +* or 'minors' is passed to alloc_disk(). +*/ +if (partno >=disk_max_parts (disk)) +return ERR_PTR (-EINVAL ); +/* * Partitions are not supported on zoned block devices that are used as * such.
Thanks!
Bart.