Skip to contentSkip to conversation

fs: allow sendfile EOF at the file size limit

PATCH Applied Hungyu Lin 2 participants 2 messages Oct 27 – Nov 6 VFS

lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

PATCH 1/1 fs: allow sendfile EOF at the file size limit

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.

---
 fs/read_write.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/read_write.c +2 -1
index 4da846a2bf17..a25e23c6a327 100644
@@ -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;
 	}
Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw
Quoted 10 lines · Hungyu Lin

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.

[...]

Applied to the vfs-7.5.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.5.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-7.5.misc

[1/1] fs: allow sendfile EOF at the file size limit

      https://git.kernel.org/vfs/vfs/c/7c1cb643ddb7