Skip to content

Commit 3253d9d

Browse files
committed
splice: only read in as much information as there is pipe buffer space
Andreas Grünbacher reports that on the two filesystems that support iomap directio, it's possible for splice() to return -EAGAIN (instead of a short splice) if the pipe being written to has less space available in its pipe buffers than the length supplied by the calling process. Months ago we fixed splice_direct_to_actor to clamp the length of the read request to the size of the splice pipe. Do the same to do_splice. Fixes: 1761444 ("splice: don't read more than available pipe space") Reported-by: [email protected] Reported-by: Andreas Grünbacher <[email protected]> Reviewed-by: Andreas Grünbacher <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 4f5cafb commit 3253d9d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

fs/splice.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -945,12 +945,13 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
945945
WARN_ON_ONCE(pipe->nrbufs != 0);
946946

947947
while (len) {
948+
unsigned int pipe_pages;
948949
size_t read_len;
949950
loff_t pos = sd->pos, prev_pos = pos;
950951

951952
/* Don't try to read more the pipe has space for. */
952-
read_len = min_t(size_t, len,
953-
(pipe->buffers - pipe->nrbufs) << PAGE_SHIFT);
953+
pipe_pages = pipe->buffers - pipe->nrbufs;
954+
read_len = min(len, (size_t)pipe_pages << PAGE_SHIFT);
954955
ret = do_splice_to(in, &pos, pipe, read_len, flags);
955956
if (unlikely(ret <= 0))
956957
goto out_release;
@@ -1180,8 +1181,15 @@ static long do_splice(struct file *in, loff_t __user *off_in,
11801181

11811182
pipe_lock(opipe);
11821183
ret = wait_for_space(opipe, flags);
1183-
if (!ret)
1184+
if (!ret) {
1185+
unsigned int pipe_pages;
1186+
1187+
/* Don't try to read more the pipe has space for. */
1188+
pipe_pages = opipe->buffers - opipe->nrbufs;
1189+
len = min(len, (size_t)pipe_pages << PAGE_SHIFT);
1190+
11841191
ret = do_splice_to(in, &offset, opipe, len, flags);
1192+
}
11851193
pipe_unlock(opipe);
11861194
if (ret > 0)
11871195
wakeup_pipe_readers(opipe);

0 commit comments

Comments
 (0)