[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAFhGd8opxHhTdZhDg_hq7XWQFxJ34nLDxTd-nBBgye9BLohnqw@mail.gmail.com>
Date: Thu, 9 May 2024 15:10:07 -0700
From: Justin Stitt <justinstitt@...gle.com>
To: Jan Kara <jack@...e.cz>
Cc: Alexander Viro <viro@...iv.linux.org.uk>, Christian Brauner <brauner@...nel.org>,
Nathan Chancellor <nathan@...nel.org>, Bill Wendling <morbo@...gle.com>, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org, llvm@...ts.linux.dev,
linux-hardening@...r.kernel.org
Subject: Re: [PATCH] fs: remove accidental overflow during wraparound check
On Thu, May 9, 2024 at 8:53 AM Jan Kara <jack@...e.cz> 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@...e.com>
> SUSE Labs, CR
Powered by blists - more mailing lists