From: Al Viro <viro@zeniv.linux.org.uk>
To: Justin Stitt <justinstitt@google.com>
Cc: Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
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] libfs: fix accidental overflow in offset calculation
Date: Fri, 10 May 2024 02:04:51 +0100 [thread overview]
Message-ID: <20240510010451.GV2118490@ZenIV> (raw)
In-Reply-To: <20240510004906.GU2118490@ZenIV>
On Fri, May 10, 2024 at 01:49:06AM +0100, Al Viro wrote:
> On Fri, May 10, 2024 at 12:35:51AM +0000, Justin Stitt wrote:
> > @@ -147,7 +147,9 @@ loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence)
> > struct dentry *dentry = file->f_path.dentry;
> > switch (whence) {
> > case 1:
> > - offset += file->f_pos;
> > + /* cannot represent offset with loff_t */
> > + if (check_add_overflow(offset, file->f_pos, &offset))
> > + return -EOVERFLOW;
>
> Instead of -EINVAL it correctly returns in such cases? Why?
We have file->f_pos in range 0..LLONG_MAX. We are adding a value in
range LLONG_MIN..LLONG_MAX. The sum (in $\Bbb Z$) cannot be below
LLONG_MIN or above 2 * LLONG_MAX, so if it can't be represented by loff_t,
it must have been in range LLONG_MAX + 1 .. 2 * LLONG_MAX. Result of
wraparound would be equal to that sum - 2 * LLONG_MAX - 2, which is going
to be in no greater than -2. We will run
fallthrough;
case 0:
if (offset >= 0)
break;
fallthrough;
default:
return -EINVAL;
and fail with -EINVAL.
Could you explain why would -EOVERFLOW be preferable and why should we
engage in that bit of cargo cult?
next prev parent reply other threads:[~2024-05-10 1:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-10 0:35 [PATCH] libfs: fix accidental overflow in offset calculation Justin Stitt
2024-05-10 0:49 ` Al Viro
2024-05-10 1:04 ` Al Viro [this message]
2024-05-10 3:26 ` Justin Stitt
2024-05-10 4:48 ` Al Viro
2024-05-10 6:33 ` Al Viro
2024-05-10 7:02 ` Al Viro
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=20240510010451.GV2118490@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--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 \
/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 NNTP newsgroup(s).