Skip to content

Commit e82fc78

Browse files
Ming Leiaxboe
authored andcommitted
block: don't create too many partitions
Commit a33df75 ("block: use an xarray for disk->part_tbl") drops the check on max supported number of partitionsr, and allows partition with bigger partition numbers 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. Reviewed-by: Bart Van Assche <[email protected]> Reported-by: [email protected] Fixes: a33df75 ("block: use an xarray for disk->part_tbl") Signed-off-by: Ming Lei <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 7de55b7 commit e82fc78

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

block/partitions/core.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,13 @@ static struct block_device *add_partition(struct gendisk *disk, int partno,
322322
const char *dname;
323323
int err;
324324

325+
/*
326+
* disk_max_parts() won't be zero, either GENHD_FL_EXT_DEVT is set
327+
* or 'minors' is passed to alloc_disk().
328+
*/
329+
if (partno >= disk_max_parts(disk))
330+
return ERR_PTR(-EINVAL);
331+
325332
/*
326333
* Partitions are not supported on zoned block devices that are used as
327334
* such.

0 commit comments

Comments
 (0)