]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.4.25/tcp-fix-msg_sendpage_notlast-logic.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.4.25 / tcp-fix-msg_sendpage_notlast-logic.patch
1 From 8b19905f4cf882dc5fbc403aa3077b01e33c5b4d Mon Sep 17 00:00:00 2001
2 From: Eric Dumazet <edumazet@google.com>
3 Date: Sun, 6 Jan 2013 18:21:49 +0000
4 Subject: tcp: fix MSG_SENDPAGE_NOTLAST logic
5
6
7 From: Eric Dumazet <edumazet@google.com>
8
9 [ Upstream commit ae62ca7b03217be5e74759dc6d7698c95df498b3 ]
10
11 commit 35f9c09fe9c72e (tcp: tcp_sendpages() should call tcp_push() once)
12 added an internal flag : MSG_SENDPAGE_NOTLAST meant to be set on all
13 frags but the last one for a splice() call.
14
15 The condition used to set the flag in pipe_to_sendpage() relied on
16 splice() user passing the exact number of bytes present in the pipe,
17 or a smaller one.
18
19 But some programs pass an arbitrary high value, and the test fails.
20
21 The effect of this bug is a lack of tcp_push() at the end of a
22 splice(pipe -> socket) call, and possibly very slow or erratic TCP
23 sessions.
24
25 We should both test sd->total_len and fact that another fragment
26 is in the pipe (pipe->nrbufs > 1)
27
28 Many thanks to Willy for providing very clear bug report, bisection
29 and test programs.
30
31 Reported-by: Willy Tarreau <w@1wt.eu>
32 Bisected-by: Willy Tarreau <w@1wt.eu>
33 Tested-by: Willy Tarreau <w@1wt.eu>
34 Signed-off-by: Eric Dumazet <edumazet@google.com>
35 Signed-off-by: David S. Miller <davem@davemloft.net>
36 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
37 ---
38 fs/splice.c | 4 +++-
39 1 file changed, 3 insertions(+), 1 deletion(-)
40
41 --- a/fs/splice.c
42 +++ b/fs/splice.c
43 @@ -696,8 +696,10 @@ static int pipe_to_sendpage(struct pipe_
44 return -EINVAL;
45
46 more = (sd->flags & SPLICE_F_MORE) ? MSG_MORE : 0;
47 - if (sd->len < sd->total_len)
48 +
49 + if (sd->len < sd->total_len && pipe->nrbufs > 1)
50 more |= MSG_SENDPAGE_NOTLAST;
51 +
52 return file->f_op->sendpage(file, buf->page, buf->offset,
53 sd->len, &pos, more);
54 }