From: Al Viro <viro@zeniv.linux.org.uk>
To: mdshahid03@gmail.com
Cc: brauner@kernel.org, jack@suse.cz, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fs: sync: fix overflow check in sync_file_range()
Date: Wed, 18 Nov 2026 06:20:28 +0000 [thread overview]
Message-ID: <20261118062028.GS989762@ZenIV> (raw)
In-Reply-To: <20261118023452.48090-1-mdshahid03@gmail.com>
On Wed, Nov 18, 2026 at 08:04:52AM +0530, mdshahid03@gmail.com wrote:
> From: Mohammad Shahid <mdshahid03@gmail.com>
>
> The addition of offset and nbytes can overflow before the result
> is checked.
>
> Use check_add_overflow() to detect the overflow safely during
> addition.
"Safely" as in "doesn't rely upon the -fno-strict-overflow we
have in CFLAGS"?
> @@ -233,11 +234,13 @@ int sync_file_range(struct file *file, loff_t offset, loff_t nbytes,
> if (flags & ~VALID_FLAGS)
> goto out;
>
> - endbyte = offset + nbytes;
> + if (offset < 0)
> + goto out;
>
> - if ((s64)offset < 0)
> + if (check_add_overflow(offset, nbytes, &endbyte))
> goto out;
> - if ((s64)endbyte < 0)
> +
> + if (endbyte < 0)
> goto out;
> if (endbyte < offset)
> goto out;
Why do you keep the old overflow check after having added that thing?
If sum of two non-negative long long values does *not* wrap around,
it will never be below either of summands; that's what the last check
had always been about. I'm not saying that it's worse off with
the use of check_add_overflow(), but mixing it with the old overflow
check is very confusing...
prev parent reply other threads:[~2026-11-18 6:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 2:34 [PATCH] fs: sync: fix overflow check in sync_file_range() mdshahid03
2026-11-18 6:20 ` Al Viro [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=20261118062028.GS989762@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mdshahid03@gmail.com \
/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