Skip to content

Commit f658ade

Browse files
author
Miklos Szeredi
committed
fix up iter on short count in fuse_direct_io()
fuse_direct_io() can end up advancing the iterator by more than the amount of data read or written. This case is handled by the generic code if going through ->direct_IO(), but not in the FOPEN_DIRECT_IO case. Fix by reverting the extra bytes from the iterator in case of error or a short count. To test: install lxcfs, then the following testcase int fd = open("/var/lib/lxcfs/proc/uptime", O_RDONLY); sendfile(1, fd, NULL, 16777216); sendfile(1, fd, NULL, 16777216); will spew WARN_ON() in iov_iter_pipe(). Reported-by: Peter Geis <[email protected]> Reported-by: Al Viro <[email protected]> Fixes: 3c3db09 ("fuse: use iov_iter based generic splice helpers") Cc: <[email protected]> # v5.1 Signed-off-by: Miklos Szeredi <[email protected]>
1 parent d5226fa commit f658ade

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

fs/fuse/file.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,7 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
14651465
}
14661466
ia = NULL;
14671467
if (nres < 0) {
1468+
iov_iter_revert(iter, nbytes);
14681469
err = nres;
14691470
break;
14701471
}
@@ -1473,8 +1474,10 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
14731474
count -= nres;
14741475
res += nres;
14751476
pos += nres;
1476-
if (nres != nbytes)
1477+
if (nres != nbytes) {
1478+
iov_iter_revert(iter, nbytes - nres);
14771479
break;
1480+
}
14781481
if (count) {
14791482
max_pages = iov_iter_npages(iter, fc->max_pages);
14801483
ia = fuse_io_alloc(io, max_pages);

0 commit comments

Comments
 (0)