Unverified Commit 366d3a80 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!4742 block: add check that partition length needs to be aligned with block size

parents 14d5d31a d3684416
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ static int blkpg_do_ioctl(struct block_device *bdev,
			  struct blkpg_partition __user *upart, int op)
{
	struct blkpg_partition p;
	long long start, length;
	sector_t start, length;

	if (!capable(CAP_SYS_ADMIN))
		return -EACCES;
@@ -34,6 +34,9 @@ static int blkpg_do_ioctl(struct block_device *bdev,

	if (p.start < 0 || p.length <= 0 || p.start + p.length < 0)
		return -EINVAL;
	/* Check that the partition is aligned to the block size */
	if (!IS_ALIGNED(p.start | p.length, bdev_logical_block_size(bdev)))
		return -EINVAL;

	start = p.start >> SECTOR_SHIFT;
	length = p.length >> SECTOR_SHIFT;
@@ -53,9 +56,6 @@ static int blkpg_do_ioctl(struct block_device *bdev,

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