Skip to content

Commit ff17119

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 f5a425f commit ff17119

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
@@ -1663,11 +1663,13 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc,
16631663
if (!copied)
16641664
copied = used;
16651665
break;
1666-
} else if (used <= len) {
1667-
seq += used;
1668-
copied += used;
1669-
offset += used;
16701666
}
1667+
if (WARN_ON_ONCE(used > len))
1668+
used = len;
1669+
seq += used;
1670+
copied += used;
1671+
offset += used;
1672+
16711673
/* If recv_actor drops the lock (e.g. TCP splice
16721674
* receive) the skb pointer might be invalid when
16731675
* getting here: tcp_collapse might have deleted it

0 commit comments

Comments
 (0)