Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Min Li and committed by
Jens Axboe
6d4e80db 9a72a024

+11
+11
block/partitions/core.c
··· 441 441 int bdev_add_partition(struct gendisk *disk, int partno, sector_t start, 442 442 sector_t length) 443 443 { 444 + sector_t capacity = get_capacity(disk), end; 444 445 struct block_device *part; 445 446 int ret; 446 447 447 448 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 + 448 459 if (!disk_live(disk)) { 449 460 ret = -ENXIO; 450 461 goto out;