From: mdshahid03@gmail.com
To: viro@zeniv.linux.org.uk
Cc: brauner@kernel.org, jack@suse.cz, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org,
Mohammad Shahid <mdshahid03@gmail.com>
Subject: [PATCH v2] fs: sync: fix overflow check in sync_file_range()
Date: Thu, 19 Nov 2026 11:08:27 +0530 [thread overview]
Message-ID: <20261119053827.69933-1-mdshahid03@gmail.com> (raw)
From: Mohammad Shahid <mdshahid03@gmail.com>
Use check_add_overflow() to detect overflow when calculating
the end byte of the requested range.
Reject negative offsets and lengths before performing the
addition.
Signed-off-by: Mohammad Shahid <mdshahid03@gmail.com>
---
fs/sync.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/fs/sync.c b/fs/sync.c
index 4a84dd837b86..a1ef2b619cfc 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -10,6 +10,7 @@
#include <linux/slab.h>
#include <linux/export.h>
#include <linux/namei.h>
+#include <linux/overflow.h>
#include <linux/sched.h>
#include <linux/writeback.h>
#include <linux/syscalls.h>
@@ -233,13 +234,10 @@ int sync_file_range(struct file *file, loff_t offset, loff_t nbytes,
if (flags & ~VALID_FLAGS)
goto out;
- endbyte = offset + nbytes;
-
- if ((s64)offset < 0)
- goto out;
- if ((s64)endbyte < 0)
+ if (offset < 0 || nbytes < 0)
goto out;
- if (endbyte < offset)
+
+ if (check_add_overflow(offset, nbytes, &endbyte))
goto out;
if (sizeof(pgoff_t) == 4) {
--
2.43.0
reply other threads:[~2026-11-19 5:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261119053827.69933-1-mdshahid03@gmail.com \
--to=mdshahid03@gmail.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.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
all inboxes | Powered by JetHome®