Skip to content

Commit

Permalink
block: don't create too many partitions
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Ming Lei authored and axboe committed Mar 27, 2021
1 parent 7de55b7 commit e82fc78
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions block/partitions/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e82fc78

Please sign in to comment.