Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Justin Stitt <justinstitt@google.com>
Cc: Jan Kara <jack@suse.cz>, Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Bill Wendling <morbo@google.com>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev, linux-hardening@vger.kernel.org
Subject: Re: [PATCH] fs: remove accidental overflow during wraparound check
Date: Sun, 12 May 2024 10:05:11 +0200	[thread overview]
Message-ID: <20240512080511.yotlypw35qowwjoh@quack3> (raw)
In-Reply-To: <CAFhGd8opxHhTdZhDg_hq7XWQFxJ34nLDxTd-nBBgye9BLohnqw@mail.gmail.com>

On Thu 09-05-24 15:10:07, Justin Stitt wrote:
> On Thu, May 9, 2024 at 8:53 AM Jan Kara <jack@suse.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.

Well, for normal readers offset+len is always a positive number. That's
what you expect. If you see a check for offset+len < 0, you start wondering
what are you missing... only to find you miss nothing and the check is
pointless. So yes, please send a version without the pointless check.

								Honza

-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

      reply	other threads:[~2024-05-13 13:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-07 23:17 [PATCH] fs: remove accidental overflow during wraparound check Justin Stitt
2024-05-08  0:10 ` Al Viro
2024-05-08  0:11 ` Kees Cook
2024-05-09 15:53 ` Jan Kara
2024-05-09 22:10   ` Justin Stitt
2024-05-12  8:05     ` Jan Kara [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240512080511.yotlypw35qowwjoh@quack3 \
    --to=jack@suse.cz \
    --cc=brauner@kernel.org \
    --cc=justinstitt@google.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).