]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tcp: fix return value for partial writes
authorEric Dumazet <edumazet@google.com>
Wed, 2 Nov 2016 21:41:50 +0000 (14:41 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 21 Nov 2016 09:11:34 +0000 (10:11 +0100)
[ Upstream commit 79d8665b9545e128637c51cf7febde9c493b6481 ]

After my commit, tcp_sendmsg() might restart its loop after
processing socket backlog.

If sk_err is set, we blindly return an error, even though we
copied data to user space before.

We should instead return number of bytes that could be copied,
otherwise user space might resend data and corrupt the stream.

This might happen if another thread is using recvmsg(MSG_ERRQUEUE)
to process timestamps.

Issue was diagnosed by Soheil and Willem, big kudos to them !

Fixes: d41a69f1d390f ("tcp: make tcp_sendmsg() aware of socket backlog")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Willem de Bruijn <willemb@google.com>
Cc: Soheil Hassas Yeganeh <soheil@google.com>
Cc: Yuchung Cheng <ycheng@google.com>
Cc: Neal Cardwell <ncardwell@google.com>
Tested-by: Soheil Hassas Yeganeh <soheil@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/ipv4/tcp.c

index e5d11df756702c69cb930445c9111594ebbac19d..c876f5ddc86c32475b2fd067950b5b74bba7be4a 100644 (file)
@@ -1145,7 +1145,7 @@ restart:
 
        err = -EPIPE;
        if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN))
-               goto out_err;
+               goto do_error;
 
        sg = !!(sk->sk_route_caps & NETIF_F_SG);