Skip to content

Commit

Permalink
fix writev regression: pan hanging unkillable and un-straceable
Browse files Browse the repository at this point in the history
Frederik Himpe reported an unkillable and un-straceable pan process.

Zero length iovecs can go into an infinite loop in writev, because the
iovec iterator does not always advance over them.

The sequence required to trigger this is not trivial. I think it
requires that a zero-length iovec be followed by a non-zero-length iovec
which causes a pagefault in the atomic usercopy. This causes the writev
code to drop back into single-segment copy mode, which then tries to
copy the 0 bytes of the zero-length iovec; a zero length copy looks like
a failure though, so it loops.

Put a test into iov_iter_advance to catch zero-length iovecs. We could
just put the test in the fallback path, but I feel it is more robust to
skip over zero-length iovecs throughout the code (iovec iterator may be
used in filesystems too, so it should be robust).

Signed-off-by: Nick Piggin <npiggin@suse.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Nick Piggin authored and torvalds committed Feb 2, 2008
1 parent 6598b60 commit 124d3b7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mm/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,11 @@ static void __iov_iter_advance_iov(struct iov_iter *i, size_t bytes)
const struct iovec *iov = i->iov;
size_t base = i->iov_offset;

while (bytes) {
/*
* The !iov->iov_len check ensures we skip over unlikely
* zero-length segments.
*/
while (bytes || !iov->iov_len) {
int copy = min(bytes, iov->iov_len - base);

bytes -= copy;
Expand Down Expand Up @@ -2268,6 +2272,7 @@ static ssize_t generic_perform_write(struct file *file,

cond_resched();

iov_iter_advance(i, copied);
if (unlikely(copied == 0)) {
/*
* If we were unable to copy any data at all, we must
Expand All @@ -2281,7 +2286,6 @@ static ssize_t generic_perform_write(struct file *file,
iov_iter_single_seg_count(i));
goto again;
}
iov_iter_advance(i, copied);
pos += copied;
written += copied;

Expand Down

0 comments on commit 124d3b7

Please # to comment.