tcp: skip DSACKs with dubious sequence ranges
Subsystems (3)
PATCH 1/1 tcp: skip DSACKs with dubious sequence ranges
From: Priyaranjan Jha <[email protected]>
Currently, we use length of DSACKed range to compute number of delivered packets. And if sequence range in DSACK is corrupted, we can get bogus dsacked/acked count, and bogus cwnd.
This patch put bounds on DSACKed range to skip update of data delivery and spurious retransmission information, if the DSACK is unlikely caused by sender's action:
- DSACKed range shouldn't be greater than maximum advertised rwnd.
- Total no. of DSACKed segments shouldn't be greater than total no. of retransmitted segs. Unlike spurious retransmits, network duplicates or corrupted DSACKs shouldn't be counted as delivery.
--- include/uapi/linux/snmp.h | 1 + net/ipv4/proc.c | 1 + net/ipv4/tcp_input.c | 32 +++++++++++++++++++++++++------- 3 files changed, 27 insertions(+), 7 deletions(-)
include/uapi/linux/snmp.h +1 -0
@@ -288,6 +288,7 @@ enumLINUX_MIB_TCPTIMEOUTREHASH ,/* TCPTimeoutRehash */ LINUX_MIB_TCPDUPLICATEDATAREHASH ,/* TCPDuplicateDataRehash */ LINUX_MIB_TCPDSACKRECVSEGS ,/* TCPDSACKRecvSegs */ +LINUX_MIB_TCPDSACKIGNOREDDUBIOUS ,/* TCPDSACKIgnoredDubious */ __LINUX_MIB_MAX };
net/ipv4/proc.c +1 -0
@@ -293,6 +293,7 @@ static const struct snmp_mib snmp4_net_list[] = {SNMP_MIB_ITEM ("TcpTimeoutRehash" ,LINUX_MIB_TCPTIMEOUTREHASH ),SNMP_MIB_ITEM ("TcpDuplicateDataRehash" ,LINUX_MIB_TCPDUPLICATEDATAREHASH ),SNMP_MIB_ITEM ("TCPDSACKRecvSegs" ,LINUX_MIB_TCPDSACKRECVSEGS ), +SNMP_MIB_ITEM ("TCPDSACKIgnoredDubious" ,LINUX_MIB_TCPDSACKIGNOREDDUBIOUS ), SNMP_MIB_SENTINEL };
net/ipv4/tcp_input.c +25 -7
@@ -885,21 +885,34 @@ struct tcp_sacktag_state {struct rate_sample *rate; }; -/* Take a notice that peer is sending D-SACKs */ +/* Take a notice that peer is sending D-SACKs. Skip update of data delivery +* and spurious retransmission information if this DSACK is unlikely caused by +* sender's action: +* - DSACKed sequence range is larger than maximum receiver's window. +* - Total no. of DSACKed segments exceed the total no. of retransmitted segs. +*/ static u32 tcp_dsack_seen (struct tcp_sock *tp,u32 start_seq,u32 end_seq,struct tcp_sacktag_state *state) {u32 seq_len, dup_segs =1 ; -if (before (start_seq, end_seq)) { - seq_len = end_seq - start_seq; -if (seq_len > tp->mss_cache) - dup_segs =DIV_ROUND_UP (seq_len, tp->mss_cache); - } +if (!before (start_seq, end_seq)) +return 0 ; + + seq_len = end_seq - start_seq; +/* Dubious DSACK: DSACKed range greater than maximum advertised rwnd */ +if (seq_len > tp->max_window) +return 0 ; +if (seq_len > tp->mss_cache) + dup_segs =DIV_ROUND_UP (seq_len, tp->mss_cache); + + tp->dsack_dups += dup_segs; +/* Skip the DSACK if dup segs weren't retransmitted by sender */ +if (tp->dsack_dups > tp->total_retrans) +return 0 ; tp->rx_opt.sack_ok |=TCP_DSACK_SEEN ; tp->rack.dsack_seen =1 ; - tp->dsack_dups += dup_segs; state->flag |=FLAG_DSACKING_ACK ;/* A spurious retransmission is delivered */
@@ -1153,6 +1166,11 @@ static bool tcp_check_dsack(struct sock *sk, const struct sk_buff *ack_skb, } dup_segs =tcp_dsack_seen (tp, start_seq_0, end_seq_0, state); +if (!dup_segs) {/* Skip dubious DSACK */ +NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPDSACKIGNOREDDUBIOUS ); +return false; + } +NET_ADD_STATS (sock_net (sk),LINUX_MIB_TCPDSACKRECVSEGS , dup_segs);/* D-SACK for already forgotten data... Do dumb counting. */
Signature · 1 line
2.28.0.681.g6f77f65b4e-goog
David Miller
maintainerFrom: Priyaranjan Jha <[email protected]>
Date: Thu, 24 Sep 2020 15:23:14 -0700
Quoted 14 lines
From: Priyaranjan Jha <[email protected]>
Currently, we use length of DSACKed range to compute number of delivered packets. And if sequence range in DSACK is corrupted, we can get bogus dsacked/acked count, and bogus cwnd.
This patch put bounds on DSACKed range to skip update of data delivery and spurious retransmission information, if the DSACK is unlikely caused by sender's action:
- DSACKed range shouldn't be greater than maximum advertised rwnd.
- Total no. of DSACKed segments shouldn't be greater than total no. of retransmitted segs. Unlike spurious retransmits, network duplicates or corrupted DSACKs shouldn't be counted as delivery.
Quoted 4 lines
Signed-off-by Priyaranjan Jha <[email protected]>Signed-off-by Neal Cardwell <[email protected]>Signed-off-by Yuchung Cheng <[email protected]>Signed-off-by Eric Dumazet <[email protected]>
Applied and queued up for -stable, thanks.