fs: skip copy_file_range write limits when there is no data
Subsystems (2)
PATCH 1/1 fs: skip copy_file_range write limits when there is no data
generic_copy_file_checks() reduces count to zero for a source offset at or beyond EOF, but still checks the destination write limits. If pos_out is at RLIMIT_FSIZE, this sends SIGXFSZ and returns -EFBIG even though there is no data to write.
For example, GNU cat copying a 1024-byte regular file to another regular file with RLIMIT_FSIZE=1024 copies all bytes and is then killed by its next copy_file_range() call at EOF. A zero-length request can fail in the same way.
Check write limits only when count is nonzero, as the ordinary write checks already do. Keep the other copy validation in place.
--- fs/read_write.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
fs/read_write.c +5 -3
@@ -1531,9 +1531,11 @@ static int generic_copy_file_checks(struct file *file_in, loff_t pos_in,else count =min (count, size_in - (uint64_t )pos_in); - ret =generic_write_check_limits (file_out, pos_out, &count); -if (ret) -return ret; +if (count) { + ret =generic_write_check_limits (file_out, pos_out, &count); +if (ret) +return ret; + }/* Don't allow overlapped copying within the same file. */ if (inode_in == inode_out &&
Signature · 1 line
2.43.0
Quoted 11 lines · Hungyu Lin
generic_copy_file_checks()reduces count to zero for a source offset at or beyond EOF, but still checks the destination write limits. Ifpos_outis atRLIMIT_FSIZE, this sends SIGXFSZ and returns-EFBIGeven though there is no data to write.For example, GNU cat copying a 1024-byte regular file to another regular file with RLIMIT_FSIZE=1024 copies all bytes and is then killed by its next
copy_file_range()call at EOF. A zero-length request can fail in the same way.
Quoted 6 lines
Check write limits only when count is nonzero, as the ordinary write checks already do. Keep the other copy validation in place.
Fixes 96e6e8f4a68d ("vfs: add missing checks to copy_file_range")Signed-off-by Hungyu Lin <[email protected]>
Thanks for the fix!
Quoted 26 lines
--- fs/read_write.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)fs/read_write.c +5
-4@@ -1531,9 +1531,11 @@ static int generic_copy_file_checks(struct file *file_in, loff_t pos_in,else count =min (count, size_in - (uint64_t )pos_in); - ret =generic_write_check_limits (file_out, pos_out, &count); -if (ret) -return ret; +if (count) { + ret =generic_write_check_limits (file_out, pos_out, &count); +if (ret) +return ret; + }/* Don't allow overlapped copying within the same file. */ if (inode_in == inode_out && --2.43.0
Quoted 11 lines · Hungyu Lin
generic_copy_file_checks()reduces count to zero for a source offset at or beyond EOF, but still checks the destination write limits. Ifpos_outis atRLIMIT_FSIZE, this sends SIGXFSZ and returns-EFBIGeven though there is no data to write.For example, GNU cat copying a 1024-byte regular file to another regular file with RLIMIT_FSIZE=1024 copies all bytes and is then killed by its next
copy_file_range()call at EOF. A zero-length request can fail in the same way.[...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes 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.fixes
[1/1] fs: skip copy_file_range write limits when there is no data
https://git.kernel.org/vfs/vfs/c/81dfa035891f