diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2022-06-12 19:50:29 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2022-08-17 14:22:51 +0200 |
commit | 4228c037f88ef3c67a396a1de324650605ecbcef (patch) | |
tree | da325de08e8df3c0fd7689a51702de622cb056aa /lib | |
parent | 635fd8953e4309b54ca6a81bed1d4a87668694f4 (diff) | |
download | linux-stable-4228c037f88ef3c67a396a1de324650605ecbcef.tar.gz linux-stable-4228c037f88ef3c67a396a1de324650605ecbcef.tar.bz2 linux-stable-4228c037f88ef3c67a396a1de324650605ecbcef.zip |
fix short copy handling in copy_mc_pipe_to_iter()
commit c3497fd009ef2c59eea60d21c3ac22de3585ed7d upstream.
Unlike other copying operations on ITER_PIPE, copy_mc_to_iter() can
result in a short copy. In that case we need to trim the unused
buffers, as well as the length of partially filled one - it's not
enough to set ->head, ->iov_offset and ->count to reflect how
much had we copied. Not hard to fix, fortunately...
I'd put a helper (pipe_discard_from(pipe, head)) into pipe_fs_i.h,
rather than iov_iter.c - it has nothing to do with iov_iter and
having it will allow us to avoid an ugly kludge in fs/splice.c.
We could put it into lib/iov_iter.c for now and move it later,
but I don't see the point going that way...
Cc: stable@kernel.org # 4.19+
Fixes: ca146f6f091e "lib/iov_iter: Fix pipe handling in _copy_to_iter_mcsafe()"
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/iov_iter.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 6cf2d66fb839..d0c3e939ee60 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -691,6 +691,7 @@ static size_t copy_mc_pipe_to_iter(const void *addr, size_t bytes, struct pipe_inode_info *pipe = i->pipe; unsigned int p_mask = pipe->ring_size - 1; unsigned int i_head; + unsigned int valid = pipe->head; size_t n, off, xfer = 0; if (!sanity(i)) @@ -704,11 +705,17 @@ static size_t copy_mc_pipe_to_iter(const void *addr, size_t bytes, rem = copy_mc_to_kernel(p + off, addr + xfer, chunk); chunk -= rem; kunmap_local(p); - i->head = i_head; - i->iov_offset = off + chunk; - xfer += chunk; - if (rem) + if (chunk) { + i->head = i_head; + i->iov_offset = off + chunk; + xfer += chunk; + valid = i_head + 1; + } + if (rem) { + pipe->bufs[i_head & p_mask].len -= rem; + pipe_discard_from(pipe, valid); break; + } n -= chunk; off = 0; i_head++; |