Skip to content

Commit e3d5ea2

Browse files
edumazetkuba-moo
authored andcommitted
tcp: make tcp_read_sock() more robust
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 <[email protected]> Acked-by: John Fastabend <[email protected]> Acked-by: Jakub Sitnicki <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 60ce37b commit e3d5ea2

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

net/ipv4/tcp.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,11 +1684,13 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc,
16841684
if (!copied)
16851685
copied = used;
16861686
break;
1687-
} else if (used <= len) {
1688-
seq += used;
1689-
copied += used;
1690-
offset += used;
16911687
}
1688+
if (WARN_ON_ONCE(used > len))
1689+
used = len;
1690+
seq += used;
1691+
copied += used;
1692+
offset += used;
1693+
16921694
/* If recv_actor drops the lock (e.g. TCP splice
16931695
* receive) the skb pointer might be invalid when
16941696
* getting here: tcp_collapse might have deleted it

0 commit comments

Comments
 (0)