Skip to content

Commit 4027803

Browse files
Min LisfX-bot
Min Li
authored andcommitted
block: add check that partition length needs to be aligned with block size
commit 6f64f866aa1ae6975c95d805ed51d7e9433a0016 upstream. 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: <[email protected]> Signed-off-by: Min Li <[email protected]> Reviewed-by: Damien Le Moal <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Ashwin Dayanand Kamat <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c3eca1f commit 4027803

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

block/ioctl.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static int blkpg_do_ioctl(struct block_device *bdev,
1717
struct blkpg_partition __user *upart, int op)
1818
{
1919
struct blkpg_partition p;
20-
long long start, length;
20+
sector_t start, length;
2121

2222
if (!capable(CAP_SYS_ADMIN))
2323
return -EACCES;
@@ -32,6 +32,12 @@ static int blkpg_do_ioctl(struct block_device *bdev,
3232
if (op == BLKPG_DEL_PARTITION)
3333
return bdev_del_partition(bdev, p.pno);
3434

35+
if (p.start < 0 || p.length <= 0 || p.start + p.length < 0)
36+
return -EINVAL;
37+
/* Check that the partition is aligned to the block size */
38+
if (!IS_ALIGNED(p.start | p.length, bdev_logical_block_size(bdev)))
39+
return -EINVAL;
40+
3541
start = p.start >> SECTOR_SHIFT;
3642
length = p.length >> SECTOR_SHIFT;
3743

@@ -46,9 +52,6 @@ static int blkpg_do_ioctl(struct block_device *bdev,
4652

4753
switch (op) {
4854
case BLKPG_ADD_PARTITION:
49-
/* check if partition is aligned to blocksize */
50-
if (p.start & (bdev_logical_block_size(bdev) - 1))
51-
return -EINVAL;
5255
return bdev_add_partition(bdev, p.pno, start, length);
5356
case BLKPG_RESIZE_PARTITION:
5457
return bdev_resize_partition(bdev, p.pno, start, length);

0 commit comments

Comments
 (0)