Re: [PATCH vfs.all 04/26] block: prevent direct access of bd_inode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Apr 07, 2024 at 10:37:08AM +0800, Yu Kuai wrote:
> Hi,
> 
> 在 2024/04/07 10:22, Al Viro 写道:
> > On Sat, Apr 06, 2024 at 05:09:08PM +0800, Yu Kuai wrote:
> > > @@ -669,7 +669,7 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
> > >   {
> > >   	struct file *file = iocb->ki_filp;
> > >   	struct block_device *bdev = I_BDEV(file->f_mapping->host);
> > > -	struct inode *bd_inode = bdev->bd_inode;
> > > +	struct inode *bd_inode = bdev_inode(bdev);
> > 
> > What you want here is this:
> > 
> > 	struct inode *bd_inode = file->f_mapping->host;
> > 	struct block_device *bdev = I_BDEV(bd_inode);
> 
> Yes, this way is better, logically.
> > 
> > 
> > > --- a/block/ioctl.c
> > > +++ b/block/ioctl.c
> > > @@ -97,7 +97,7 @@ static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode,
> > >   {
> > >   	uint64_t range[2];
> > >   	uint64_t start, len;
> > > -	struct inode *inode = bdev->bd_inode;
> > > +	struct inode *inode = bdev_inode(bdev);
> > >   	int err;
> > 
> > The uses of 'inode' in this function are
> >          filemap_invalidate_lock(inode->i_mapping);
> > and
> >          filemap_invalidate_unlock(inode->i_mapping);
> > 
> > IOW, you want bdev_mapping(bdev), not bdev_inode(bdev).
> > 
> > > @@ -166,7 +166,7 @@ static int blk_ioctl_zeroout(struct block_device *bdev, blk_mode_t mode,
> > >   {
> > >   	uint64_t range[2];
> > >   	uint64_t start, end, len;
> > > -	struct inode *inode = bdev->bd_inode;
> > > +	struct inode *inode = bdev_inode(bdev);
> > 
> > Same story.
> 
> Yes.

I've folded in those changes during applying.




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux