Skip to content

Commit

Permalink
iov_iter_advance(): use consistent semantics for move past the end
Browse files Browse the repository at this point in the history
[ Upstream commit 3b3fc05 ]

asking to advance by more than we have left in the iov_iter should
move to the very end; it should *not* leave negative i->count and
it should not spew into syslog, etc. - it's a legitimate operation.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Al Viro authored and gregkh committed Jul 20, 2021
1 parent a3a1178 commit ed8c2cc
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/iov_iter.c
Expand Up @@ -1117,8 +1117,6 @@ static inline void pipe_truncate(struct iov_iter *i)
static void pipe_advance(struct iov_iter *i, size_t size)
{
struct pipe_inode_info *pipe = i->pipe;
if (unlikely(i->count < size))
size = i->count;
if (size) {
struct pipe_buffer *buf;
unsigned int p_mask = pipe->ring_size - 1;
Expand Down Expand Up @@ -1159,6 +1157,8 @@ static void iov_iter_bvec_advance(struct iov_iter *i, size_t size)

void iov_iter_advance(struct iov_iter *i, size_t size)
{
if (unlikely(i->count < size))
size = i->count;
if (unlikely(iov_iter_is_pipe(i))) {
pipe_advance(i, size);
return;
Expand All @@ -1168,7 +1168,6 @@ void iov_iter_advance(struct iov_iter *i, size_t size)
return;
}
if (unlikely(iov_iter_is_xarray(i))) {
size = min(size, i->count);
i->iov_offset += size;
i->count -= size;
return;
Expand Down

0 comments on commit ed8c2cc

Please sign in to comment.