Skip to content

Commit ec05759

Browse files
committed
pipe: fix incorrect caching of pipe state over pipe_wait()
Similarly to commit 8f868d6 ("pipe: Fix missing mask update after pipe_wait()") this fixes a case where the pipe rewrite ended up caching the pipe state incorrectly over a pipe lock drop event. It wasn't quite as obvious, because you needed to splice data from a pipe to a file, which is a fairly unusual operation, but it's completely wrong. Make sure we load the pipe head/tail/size information only after we've waited for there to be data in the pipe. While in that file, also make one of the splice helper functions use the canonical arghument order for pipe_empty(). That's syntactic - pipe emptiness is just that head and tail are equal, and thus mixing up head and tail doesn't really matter. It's still wrong, though. Reported-by: David Sterba <[email protected]> Cc: David Howells <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 7ada90e commit ec05759

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

fs/splice.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
495495
unsigned int mask = pipe->ring_size - 1;
496496
int ret;
497497

498-
while (!pipe_empty(tail, head)) {
498+
while (!pipe_empty(head, tail)) {
499499
struct pipe_buffer *buf = &pipe->bufs[tail & mask];
500500

501501
sd->len = buf->len;
@@ -711,9 +711,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
711711
splice_from_pipe_begin(&sd);
712712
while (sd.total_len) {
713713
struct iov_iter from;
714-
unsigned int head = pipe->head;
715-
unsigned int tail = pipe->tail;
716-
unsigned int mask = pipe->ring_size - 1;
714+
unsigned int head, tail, mask;
717715
size_t left;
718716
int n;
719717

@@ -732,6 +730,10 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
732730
}
733731
}
734732

733+
head = pipe->head;
734+
tail = pipe->tail;
735+
mask = pipe->ring_size - 1;
736+
735737
/* build the vector */
736738
left = sd.total_len;
737739
for (n = 0; !pipe_empty(head, tail) && left && n < nbufs; tail++, n++) {

0 commit comments

Comments
 (0)