diff options
author | Eric Dumazet <edumazet@google.com> | 2022-03-02 08:17:23 -0800 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2022-03-19 13:48:45 +0100 |
commit | 09253fa62941296f0522fe72664395e3ae2445e2 (patch) | |
tree | 71acb352bfffedd21edaea67278c5129c72c4d61 | |
parent | 020419ea614b2eefbbcbd309ee0a4ececf87002d (diff) | |
download | linux-stable-09253fa62941296f0522fe72664395e3ae2445e2.tar.gz linux-stable-09253fa62941296f0522fe72664395e3ae2445e2.tar.bz2 linux-stable-09253fa62941296f0522fe72664395e3ae2445e2.zip |
tcp: make tcp_read_sock() more robust
[ Upstream commit e3d5ea2c011ecb16fb94c56a659364e6b30fac94 ]
If recv_actor() returns an incorrect value, tcp_read_sock()
might loop forever.
Instead, issue a one time warning and make sure to make progress.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Jakub Sitnicki <jakub@cloudflare.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/r/20220302161723.3910001-2-eric.dumazet@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r-- | net/ipv4/tcp.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 28abb0bb1c51..38f936785179 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1653,11 +1653,13 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc, if (!copied) copied = used; break; - } else if (used <= len) { - seq += used; - copied += used; - offset += used; } + if (WARN_ON_ONCE(used > len)) + used = len; + seq += used; + copied += used; + offset += used; + /* If recv_actor drops the lock (e.g. TCP splice * receive) the skb pointer might be invalid when * getting here: tcp_collapse might have deleted it |