vfs: generic_copy_file_checks should return EINVAL when source offset is beyond EOF
Subsystems (3)
Dai Ngo
reviewerPATCH v2 1/1 vfs: generic_copy_file_checks should return EINVAL when source offset is beyond EOF
Fix by returning -EINVAL instead of 0, per man page of copy_file_range, when the requested range extends beyond the end of the source file. Problem was discovered by subtest inter11 of nfstest_ssc.
--- fs/read_write.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/read_write.c +1 -1
@@ -1445,7 +1445,7 @@ static int generic_copy_file_checks(struct file *file_in, loff_t pos_in,/* Shorten the copy to EOF */ size_in =i_size_read (inode_in);if (pos_in >= size_in) - count =0 ; + count = -EINVAL ;else count =min (count, size_in - (uint64_t )pos_in);
Signature · 1 line
2.9.5
Quoted 1 line · Dai Ngo
Fix by returning
-EINVALinstead of 0, per man page ofcopy_file_range,
Huh? That's not what the manpage[1] says:
RETURN VALUE
Upon successful completion, copy_file_range() will return the
number of bytes copied between files. This could be less than the length originally requested. If the file offset of fd_in is at or past the end of file, no bytes are copied, and copy_file_range() returns zero.
--D
[1] https://man7.org/linux/man-pages/man2/copy_file_range.2.html#RETURN_VALUE
Quoted 24 lines
when the requested range extends beyond the end of the source file. Problem was discovered by subtest inter11 of
nfstest_ssc.Signed-off-by Dai Ngo <[email protected]>--- fs/read_write.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/read_write.c +1
-1@@ -1445,7 +1445,7 @@ static int generic_copy_file_checks(struct file *file_in, loff_t pos_in,/* Shorten the copy to EOF */ size_in =i_size_read (inode_in);if (pos_in >= size_in) - count =0 ; + count = -EINVAL ;else count =min (count, size_in - (uint64_t )pos_in);Signature · 1 line
2.9.5
[email protected]
reviewerQuoted 10 lines · Darrick J. Wong
Quoted 1 line · Dai Ngo
Fix by returning
-EINVALinstead of 0, per man page ofcopy_file_range,Huh? That's not what the manpage[1] says:
RETURN VALUE
Upon successful completion,copy_file_range()will return the
number of bytes copied between files. This could be less than the length originally requested. If the file offset offd_inis at or past the end of file, no bytes are copied, andcopy_file_range()returns zero.
In the ERROR section:
ERROR
EINVAL Requested range extends beyond the end of the source file; or the flags argument is not 0.
-Dai
Quoted 29 lines
--D
Quoted 24 lines
when the requested range extends beyond the end of the source file. Problem was discovered by subtest inter11 of
nfstest_ssc.Signed-off-by Dai Ngo <[email protected]>--- fs/read_write.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/read_write.c +1
-1@@ -1445,7 +1445,7 @@ static int generic_copy_file_checks(struct file *file_in, loff_t pos_in,/* Shorten the copy to EOF */ size_in =i_size_read (inode_in);if (pos_in >= size_in) - count =0 ; + count = -EINVAL ;else count =min (count, size_in - (uint64_t )pos_in);Signature · 1 line
2.9.5
[email protected]
reviewerHi Darrick,
My man page was out-of-date. The latest man page of coy_file_range is more clear:
This EINVAL was removed:
EINVAL Requested range extends beyond the end of the source file; or the flags argument is not 0.
and replaced with this:
*EINVAL *The/flags/ argument is not 0
Thanks,
-Dai
Quoted 49 lines · On 2/1/21 1:51 PM, [email protected] wrote:
Quoted 10 lines · Darrick J. Wong
Quoted 1 line · Dai Ngo
Fix by returning
-EINVALinstead of 0, per man page ofcopy_file_range,Huh? That's not what the manpage[1] says:
RETURN VALUE
Upon successful completion,copy_file_range()will return the number of bytes copied between files. This could be less than the length originally requested. If the file offset offd_inis at or past the end of file, no bytes are copied, andcopy_file_range()returns zero.In the ERROR section:
ERROR
EINVAL Requested range extends beyond the end of the source file; or the flags argument is not 0.-Dai
Quoted 29 lines
--D
Quoted 24 lines
when the requested range extends beyond the end of the source file. Problem was discovered by subtest inter11 of
nfstest_ssc.Signed-off-by Dai Ngo <[email protected]>---
fs/read_write.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)fs/read_write.c +1
-1@@ -1445,7 +1445,7 @@ static int generic_copy_file_checks(struct file *file_in, loff_t pos_in, /* Shorten the copy to EOF */ size_in = i_size_read(inode_in); if (pos_in >= size_in) - count = 0; + count = -EINVAL;else
count =min(count, size_in - (uint64_t)pos_in); --
2.9.5