Skip to content

Commit f112a2f

Browse files
committed
Merge tag 'vfs-5.5-merge-1' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
Pull splice fix from Darrick Wong: "Fix another place in the splice code where a pipe could ask a filesystem for a longer read than the pipe actually has free buffer space" * tag 'vfs-5.5-merge-1' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux: splice: only read in as much information as there is pipe buffer space
2 parents 3b266a5 + 3253d9d commit f112a2f

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)