From: Frank Sorenson <sorenson@redhat.com>
To: linux-cifs@vger.kernel.org, stfrench@microsoft.com, pc@manguebit.org
Cc: stable@vger.kernel.org
Subject: [PATCH 3/3] cifs: fix loff_t underflow in cifs_remap_file_range() when len == 0
Date: Thu, 6 Aug 2026 18:43:06 -0500 [thread overview]
Message-ID: <20260806234306.3662175-4-sorenson@redhat.com> (raw)
In-Reply-To: <20260806234306.3662175-1-sorenson@redhat.com>
When cifs_remap_file_range() is called with len == 0 (the clone-to-EOF
semantic), it computes the effective length as:
len = src_inode->i_size - off;
If off >= src_inode->i_size, this produces a negative loff_t that
corrupts all downstream arithmetic: filemap_write_and_wait_range() is
called with a wrapped range, and the ByteCount in the
FSCTL_DUPLICATE_EXTENTS_TO_FILE buffer receives a huge value, potentially
causing the server to attempt a multi-terabyte clone.
There is already a check for off >= src_inode->i_size at the point
where -EOPNOTSUPP is remapped to -EINVAL, but that is reached only
after the ioctl has already been sent with the corrupted length.
lock_two_nondirectories() is held at this point (i_rwsem write on both
inodes), so i_size_read() is stable. Add an early bounds check inside
the len == 0 branch and return -EINVAL via the unlock path if off is at
or beyond EOF.
Fixes: 04b38d601239 ("vfs: pull btrfs clone API to vfs layer")
Cc: stable@vger.kernel.org
Signed-off-by: Frank Sorenson <sorenson@redhat.com>
---
fs/smb/client/cifsfs.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c
index 2073b29ff969..bd4936711ced 100644
--- a/fs/smb/client/cifsfs.c
+++ b/fs/smb/client/cifsfs.c
@@ -1413,8 +1413,13 @@ static loff_t cifs_remap_file_range(struct file *src_file, loff_t off,
*/
lock_two_nondirectories(target_inode, src_inode);
- if (len == 0)
+ if (len == 0) {
+ if (off >= i_size_read(src_inode)) {
+ rc = -EINVAL;
+ goto unlock;
+ }
len = src_inode->i_size - off;
+ }
cifs_dbg(FYI, "clone range\n");
--
2.55.0
prev parent reply other threads:[~2026-08-06 23:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 23:43 [PATCH 0/3] cifs: three size-management bug fixes Frank Sorenson
2026-08-06 23:43 ` [PATCH 1/3] cifs: clear tcon after cifsFileInfo_put() in cifs_file_set_size() Frank Sorenson
2026-08-06 23:43 ` [PATCH 2/3] cifs: don't update i_size in cifs_do_truncate() without a cached handle Frank Sorenson
2026-08-06 23:43 ` Frank Sorenson [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=20260806234306.3662175-4-sorenson@redhat.com \
--to=sorenson@redhat.com \
--cc=linux-cifs@vger.kernel.org \
--cc=pc@manguebit.org \
--cc=stable@vger.kernel.org \
--cc=stfrench@microsoft.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