diff --git a/mm/filemap.c b/mm/filemap.c index 5c74b68..2650073 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1750,14 +1750,18 @@ static void __iov_iter_advance_iov(struct iov_iter *i, size_t bytes) } else { const struct iovec *iov = i->iov; size_t base = i->iov_offset; + size_t copied = 0; /* * The !iov->iov_len check ensures we skip over unlikely - * zero-length segments. + * zero-length segments (without overruning the iovec). */ - while (bytes || !iov->iov_len) { - int copy = min(bytes, iov->iov_len - base); + while (copied < bytes || + unlikely(!iov->iov_len && copied < i->count)) { + int copy; + copy = min(bytes, iov->iov_len - base); + copied += copy; bytes -= copy; base += copy; if (iov->iov_len == base) {