lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ZJsiCd232pwyqhmM@casper.infradead.org>
Date:   Tue, 27 Jun 2023 18:53:13 +0100
From:   Matthew Wilcox <willy@...radead.org>
To:     Pankaj Raghav <p.raghav@...sung.com>
Cc:     Damien Le Moal <dlemoal@...nel.org>, Min Li <min15.li@...sung.com>,
        axboe@...nel.dk, hch@....de, gregkh@...uxfoundation.org,
        linux-block@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] block: add check that partition length needs to be
 aligned with block size

On Tue, Jun 27, 2023 at 10:13:39AM +0200, Pankaj Raghav wrote:
> 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;

or you can even do ...

	if (!IS_ALIGNED(p.start | p.length), blksz)

Do I win the code golf trophy?

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ