mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hungyu Lin <dennylin0707@gmail.com>
To: brauner@kernel.org, viro@zeniv.linux.org.uk
Cc: jack@suse.cz, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, dennylin0707@gmail.com
Subject: [PATCH] fs: allow sendfile EOF at the file size limit
Date: Tue, 27 Oct 2026 04:42:57 +0000	[thread overview]
Message-ID: <20261027044257.90408-1-dennylin0707@gmail.com> (raw)

do_sendfile() returns EOVERFLOW when a positive-count request starts
at the effective file size limit. If the input file ends exactly at
that limit, this rejects the final EOF probe even though no bytes
remain to be copied.

For example, Python 3.12 shutil.copyfile() copies all 4294967295 bytes
of a maximum-size FAT32 file to ext4, then raises EOVERFLOW on its
next sendfile() call instead of completing successfully.

Allow the boundary position when it matches the input file size. The
existing clamp then reduces count to zero and the remaining validation
is retained. Continue to reject positions beyond the limit and boundary
positions with input data still remaining.

Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
 fs/read_write.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index 4da846a2bf17..a25e23c6a327 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -1347,7 +1347,8 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
 		max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes);
 
 	if (unlikely(pos + count > max)) {
-		if (pos >= max)
+		if (pos > max ||
+		    (pos == max && pos != i_size_read(in_inode)))
 			return -EOVERFLOW;
 		count = max - pos;
 	}
-- 
2.43.0


                 reply	other threads:[~2026-10-27  4:43 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=20261027044257.90408-1-dennylin0707@gmail.com \
    --to=dennylin0707@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®