]> git.baikalelectronics.ru Git - kernel.git/commitdiff
splice: don't generate zero-len segement bvecs
authorPavel Begunkov <asml.silence@gmail.com>
Sat, 9 Jan 2021 16:02:57 +0000 (16:02 +0000)
committerJens Axboe <axboe@kernel.dk>
Mon, 25 Jan 2021 15:58:24 +0000 (08:58 -0700)
iter_file_splice_write() may spawn bvec segments with zero-length. In
preparation for prohibiting them, filter out by hand at splice level.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/splice.c

index 866d5c2367b233091e98e372b2ab25c04c93fef3..474fb8b5562ac6ae9784ef217505be6c36970fb0 100644 (file)
@@ -662,12 +662,14 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
 
                /* build the vector */
                left = sd.total_len;
-               for (n = 0; !pipe_empty(head, tail) && left && n < nbufs; tail++, n++) {
+               for (n = 0; !pipe_empty(head, tail) && left && n < nbufs; tail++) {
                        struct pipe_buffer *buf = &pipe->bufs[tail & mask];
                        size_t this_len = buf->len;
 
-                       if (this_len > left)
-                               this_len = left;
+                       /* zero-length bvecs are not supported, skip them */
+                       if (!this_len)
+                               continue;
+                       this_len = min(this_len, left);
 
                        ret = pipe_buf_confirm(pipe, buf);
                        if (unlikely(ret)) {
@@ -680,6 +682,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
                        array[n].bv_len = this_len;
                        array[n].bv_offset = buf->offset;
                        left -= this_len;
+                       n++;
                }
 
                iov_iter_bvec(&from, WRITE, array, n, sd.total_len - left);