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 <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Damien Le Moal <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 9a72a02 commit 6d4e80d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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)