Re: [PATCH] fs: remove accidental overflow during wraparound check

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

 



On Thu, May 9, 2024 at 8:53 AM Jan Kara <jack@xxxxxxx> wrote:
> > @@ -319,8 +320,12 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
> >       if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))
> >               return -ENODEV;
> >
> > -     /* Check for wrap through zero too */
> > -     if (((offset + len) > inode->i_sb->s_maxbytes) || ((offset + len) < 0))
> > +     /* Check for wraparound */
> > +     if (check_add_overflow(offset, len, &sum))
> > +             return -EFBIG;
> > +
> > +     /* Now, check bounds */
> > +     if (sum > inode->i_sb->s_maxbytes || sum < 0)
> >               return -EFBIG;
>
> But why do you check for sum < 0? We know from previous checks offset >= 0
> && len > 0 so unless we overflow, sum is guaranteed to be > 0.

Fair enough. I suppose with the overflow check in place we can no
longer have a sum less than zero there. If nothing else, it tells
readers of this code what the domain of (offset+len) is. I don't mind
sending a new version, though.

>
>                                                                 Honza
> --
> Jan Kara <jack@xxxxxxxx>
> SUSE Labs, CR





[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux