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 check that partition length needs to be aligned with block size

Before calling add partition or resize partition, there is no check
on whether the length is aligned with the logical block size.
If the logical block size of the disk is larger than 512 bytes,
then the partition size maybe not the multiple of the logical block size,
and when the last sector is read, bio_truncate() will adjust the bio size,
resulting in an IO error if the size of the read command is smaller than
the logical block size.If integrity data is supported, this will also
result in a null pointer dereference when calling bio_integrity_free.

Cc: <stable@vger.kernel.org>
Signed-off-by: Min Li <min15.li@samsung.com>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20230629142517.121241-1-min15.li@samsung.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Min Li and committed by
Jens Axboe
6f64f866 5fa3d1a0

+7 -4
+7 -4
block/ioctl.c
··· 18 18 { 19 19 struct gendisk *disk = bdev->bd_disk; 20 20 struct blkpg_partition p; 21 - long long start, length; 21 + sector_t start, length; 22 22 23 23 if (disk->flags & GENHD_FL_NO_PART) 24 24 return -EINVAL; ··· 35 35 if (op == BLKPG_DEL_PARTITION) 36 36 return bdev_del_partition(disk, p.pno); 37 37 38 + if (p.start < 0 || p.length <= 0 || p.start + p.length < 0) 39 + return -EINVAL; 40 + /* Check that the partition is aligned to the block size */ 41 + if (!IS_ALIGNED(p.start | p.length, bdev_logical_block_size(bdev))) 42 + return -EINVAL; 43 + 38 44 start = p.start >> SECTOR_SHIFT; 39 45 length = p.length >> SECTOR_SHIFT; 40 46 41 47 switch (op) { 42 48 case BLKPG_ADD_PARTITION: 43 - /* check if partition is aligned to blocksize */ 44 - if (p.start & (bdev_logical_block_size(bdev) - 1)) 45 - return -EINVAL; 46 49 return bdev_add_partition(disk, p.pno, start, length); 47 50 case BLKPG_RESIZE_PARTITION: 48 51 return bdev_resize_partition(disk, p.pno, start, length);