Skip to content

Commit 6d4e80d

Browse files
Min Liaxboe
authored andcommitted
block: add capacity validation in bdev_add_partition()
In the function bdev_add_partition(),there is no check that the start and end sectors exceed the size of the disk before calling add_partition. When we call the block's ioctl interface directly to add a partition, and the capacity of the disk is set to 0 by driver,the command will continue to execute. Signed-off-by: Min Li <min15.li@samsung.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Link: https://lore.kernel.org/r/20230619091214.31615-1-min15.li@samsung.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 9a72a02 commit 6d4e80d

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

block/partitions/core.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,21 @@ static bool partition_overlaps(struct gendisk *disk, sector_t start,
441441
int bdev_add_partition(struct gendisk *disk, int partno, sector_t start,
442442
sector_t length)
443443
{
444+
sector_t capacity = get_capacity(disk), end;
444445
struct block_device *part;
445446
int ret;
446447

447448
mutex_lock(&disk->open_mutex);
449+
if (check_add_overflow(start, length, &end)) {
450+
ret = -EINVAL;
451+
goto out;
452+
}
453+
454+
if (start >= capacity || end > capacity) {
455+
ret = -EINVAL;
456+
goto out;
457+
}
458+
448459
if (!disk_live(disk)) {
449460
ret = -ENXIO;
450461
goto out;

0 commit comments

Comments
 (0)