Re: [PATCH v2] block: add check that partition length needs to be aligned with block size
From: Pankaj Raghav
Date: Tue Jun 27 2023 - 04:13:53 EST
On Tue, Jun 27, 2023 at 01:39:26PM +0900, Damien Le Moal wrote:
> > diff --git a/block/ioctl.c b/block/ioctl.c
> > index 3be11941fb2d..c40b382dd58f 100644
> > --- a/block/ioctl.c
> > +++ b/block/ioctl.c
> > @@ -33,14 +33,18 @@ static int blkpg_do_ioctl(struct block_device *bdev,
> > if (op == BLKPG_DEL_PARTITION)
> > return bdev_del_partition(disk, p.pno);
> >
> > + /* check if partition is aligned to blocksize */
> > + if (p.start & (bdev_logical_block_size(bdev) - 1))
> > + return -EINVAL;
> > + /* check if length is aligned to blocksize */
> > + if (p.length & (bdev_logical_block_size(bdev) - 1))
> > + return -EINVAL;
>
> long long blksz_mask = bdev_logical_block_size(bdev) - 1;
>
> /* Check that the partition is aligned to the block size */
> if ((p.start & blksz_mask) || (p.length & blksz_mask))
> return -EINVAL;
A Minor nit on top of your comment:
unsigned int blksz = bdev_logical_block_size(bdev);
/* Check that the partition is aligned to the block size */
if (!IS_ALIGNED(p.start, blksz) || !IS_ALIGNED(p.length, blksz))
return -EINVAL;
>
> would be cleaner and avoid the rather redundant comments.
>