Skip to content

Commit

Permalink
vfs,mm: fix return value of read() at s_maxbytes
Browse files Browse the repository at this point in the history
We truncated the possible read iterator to s_maxbytes in commit
c2a9737 ("vfs,mm: fix a dead loop in truncate_inode_pages_range()"),
but our end condition handling was wrong: it's not an error to try to
read at the end of the file.

Reading past the end should return EOF (0), not EINVAL.

See for example

  https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1649342
  http://lists.gnu.org/archive/html/bug-coreutils/2016-12/msg00008.html

where a md5sum of a maximally sized file fails because the final read is
exactly at s_maxbytes.

Fixes: c2a9737 ("vfs,mm: fix a dead loop in truncate_inode_pages_range()")
Reported-by: Joseph Salisbury <[email protected]>
Cc: Wei Fang <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Dave Chinner <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: [email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
torvalds committed Dec 14, 2016
1 parent 7ae123e commit d05c5f7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mm/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ static ssize_t do_generic_file_read(struct file *filp, loff_t *ppos,
int error = 0;

if (unlikely(*ppos >= inode->i_sb->s_maxbytes))
return -EINVAL;
return 0;
iov_iter_truncate(iter, inode->i_sb->s_maxbytes);

index = *ppos >> PAGE_SHIFT;
Expand Down

0 comments on commit d05c5f7

Please sign in to comment.