* [PATCH net-next] tcp: remove redundant checks
@ 2015-06-04 6:49 Eric Dumazet
2015-06-04 8:05 ` David Miller
2015-06-04 15:01 ` [PATCH net-next] tcp: remove redundant checks II Eric Dumazet
0 siblings, 2 replies; 4+ messages in thread
From: Eric Dumazet @ 2015-06-04 6:49 UTC (permalink / raw)
To: David Miller; +Cc: netdev
From: Eric Dumazet <edumazet@google.com>
tcp_v4_rcv() checks the following before calling tcp_v4_do_rcv():
if (th->doff < sizeof(struct tcphdr) / 4)
goto bad_packet;
if (!pskb_may_pull(skb, th->doff * 4))
goto discard_it;
So following check in tcp_v4_do_rcv() is redundant
and "goto csum_err;" is wrong anyway.
if (skb->len < tcp_hdrlen(skb) || ...)
goto csum_err;
A second check can be removed after no_tcp_socket label for same reason.
Same tests can be removed in tcp_v6_do_rcv()
Note : short tcp frames are not properly accounted in tcpInErrs MIB,
because pskb_may_pull() failure simply drops incoming skb, we might
fix this in a separate patch.
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
net/ipv4/tcp_ipv4.c | 4 ++--
net/ipv6/tcp_ipv6.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index feb875769b8d57dcdb85e12b782f3f5e0fb6193a..3130c42240c86545f1037648635a9e7de0876095 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1400,7 +1400,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
return 0;
}
- if (skb->len < tcp_hdrlen(skb) || tcp_checksum_complete(skb))
+ if (tcp_checksum_complete(skb))
goto csum_err;
if (sk->sk_state == TCP_LISTEN) {
@@ -1647,7 +1647,7 @@ no_tcp_socket:
if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb))
goto discard_it;
- if (skb->len < (th->doff << 2) || tcp_checksum_complete(skb)) {
+ if (tcp_checksum_complete(skb)) {
csum_error:
TCP_INC_STATS_BH(net, TCP_MIB_CSUMERRORS);
bad_packet:
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 7be3d858cbf0a4f5b7f4ecce8788aa8e4136d6fa..b72e1ffc6bb40f486764874e6a167b72d899605b 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1250,7 +1250,7 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
return 0;
}
- if (skb->len < tcp_hdrlen(skb) || tcp_checksum_complete(skb))
+ if (tcp_checksum_complete(skb))
goto csum_err;
if (sk->sk_state == TCP_LISTEN) {
@@ -1442,7 +1442,7 @@ no_tcp_socket:
tcp_v6_fill_cb(skb, hdr, th);
- if (skb->len < (th->doff<<2) || tcp_checksum_complete(skb)) {
+ if (tcp_checksum_complete(skb)) {
csum_error:
TCP_INC_STATS_BH(net, TCP_MIB_CSUMERRORS);
bad_packet:
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH net-next] tcp: remove redundant checks
2015-06-04 6:49 [PATCH net-next] tcp: remove redundant checks Eric Dumazet
@ 2015-06-04 8:05 ` David Miller
2015-06-04 15:01 ` [PATCH net-next] tcp: remove redundant checks II Eric Dumazet
1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2015-06-04 8:05 UTC (permalink / raw)
To: eric.dumazet; +Cc: netdev
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Wed, 03 Jun 2015 23:49:21 -0700
> From: Eric Dumazet <edumazet@google.com>
>
> tcp_v4_rcv() checks the following before calling tcp_v4_do_rcv():
>
> if (th->doff < sizeof(struct tcphdr) / 4)
> goto bad_packet;
> if (!pskb_may_pull(skb, th->doff * 4))
> goto discard_it;
>
> So following check in tcp_v4_do_rcv() is redundant
> and "goto csum_err;" is wrong anyway.
>
> if (skb->len < tcp_hdrlen(skb) || ...)
> goto csum_err;
>
> A second check can be removed after no_tcp_socket label for same reason.
>
> Same tests can be removed in tcp_v6_do_rcv()
>
> Note : short tcp frames are not properly accounted in tcpInErrs MIB,
> because pskb_may_pull() failure simply drops incoming skb, we might
> fix this in a separate patch.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Looks sane, applied, thanks Eric!
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net-next] tcp: remove redundant checks II
2015-06-04 6:49 [PATCH net-next] tcp: remove redundant checks Eric Dumazet
2015-06-04 8:05 ` David Miller
@ 2015-06-04 15:01 ` Eric Dumazet
2015-06-07 8:55 ` David Miller
1 sibling, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2015-06-04 15:01 UTC (permalink / raw)
To: David Miller; +Cc: netdev
From: Eric Dumazet <edumazet@google.com>
For same reasons than in commit 12e25e1041d0 ("tcp: remove redundant
checks"), we can remove redundant checks done for timewait sockets.
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
net/ipv4/tcp_ipv4.c | 4 ----
net/ipv6/tcp_ipv6.c | 4 ----
2 files changed, 8 deletions(-)
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 3130c42240c8..d7d4c2b79cf2 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1671,10 +1671,6 @@ do_time_wait:
goto discard_it;
}
- if (skb->len < (th->doff << 2)) {
- inet_twsk_put(inet_twsk(sk));
- goto bad_packet;
- }
if (tcp_checksum_complete(skb)) {
inet_twsk_put(inet_twsk(sk));
goto csum_error;
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index b72e1ffc6bb4..45a7176ed460 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1467,10 +1467,6 @@ do_time_wait:
tcp_v6_fill_cb(skb, hdr, th);
- if (skb->len < (th->doff<<2)) {
- inet_twsk_put(inet_twsk(sk));
- goto bad_packet;
- }
if (tcp_checksum_complete(skb)) {
inet_twsk_put(inet_twsk(sk));
goto csum_error;
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-06-07 8:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-04 6:49 [PATCH net-next] tcp: remove redundant checks Eric Dumazet
2015-06-04 8:05 ` David Miller
2015-06-04 15:01 ` [PATCH net-next] tcp: remove redundant checks II Eric Dumazet
2015-06-07 8:55 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).