Skip to content

Commit 2fad5b6

Browse files
edumazetgregkh
authored andcommitted
tcp: make tcp_read_sock() more robust
[ Upstream commit e3d5ea2 ] 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>
1 parent 3f9a8f8 commit 2fad5b6

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

net/ipv4/tcp.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,11 +1652,13 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc,
16521652
if (!copied)
16531653
copied = used;
16541654
break;
1655-
} else if (used <= len) {
1656-
seq += used;
1657-
copied += used;
1658-
offset += used;
16591655
}
1656+
if (WARN_ON_ONCE(used > len))
1657+
used = len;
1658+
seq += used;
1659+
copied += used;
1660+
offset += used;
1661+
16601662
/* If recv_actor drops the lock (e.g. TCP splice
16611663
* receive) the skb pointer might be invalid when
16621664
* getting here: tcp_collapse might have deleted it

0 commit comments

Comments
 (0)