]> Git Repo - linux.git/commitdiff
tcp: make tcp_read_sock() more robust
authorEric Dumazet <[email protected]>
Wed, 2 Mar 2022 16:17:23 +0000 (08:17 -0800)
committerJakub Kicinski <[email protected]>
Thu, 3 Mar 2022 06:49:03 +0000 (22:49 -0800)
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]>
net/ipv4/tcp.c

index 02cb275e5487d98b3e124ee102163aac47b2ad6d..28ff2a820f7c935234e5ab7ecd4ed95fb7c5712a 100644 (file)
@@ -1684,11 +1684,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
This page took 0.060209 seconds and 4 git commands to generate.