Author: rscheff
Date: Wed Apr 29 22:01:33 2020
New Revision: 360479
URL: https://svnweb.freebsd.org/changeset/base/360479

Log:
  Prevent premature shrinking of the scaled receive window
  which can cause a TCP client to use invalid or stale TCP sequence numbers for 
ACK packets.
  
  Packets with old sequence numbers are ignored and not used to update the send 
window size.
  This might cause the TCP session to hang indefinitely under some 
circumstances.
  
  Reported by:  Cui Cheng
  Reviewed by:  tuexen (mentor), rgrimes (mentor)
  Approved by:  tuexen (mentor), rgrimes (mentor)
  MFC after:    3 weeks
  Sponsored by: NetApp, Inc.
  Differential Revision:        https://reviews.freebsd.org/D24515

Modified:
  head/sys/netinet/tcp_output.c
  head/sys/netinet/tcp_stacks/bbr.c
  head/sys/netinet/tcp_stacks/rack.c

Modified: head/sys/netinet/tcp_output.c
==============================================================================
--- head/sys/netinet/tcp_output.c       Wed Apr 29 21:54:09 2020        
(r360478)
+++ head/sys/netinet/tcp_output.c       Wed Apr 29 22:01:33 2020        
(r360479)
@@ -1238,8 +1238,11 @@ send:
        if (flags & TH_SYN)
                th->th_win = htons((u_short)
                                (min(sbspace(&so->so_rcv), TCP_MAXWIN)));
-       else
+       else {
+               /* Avoid shrinking window with window scaling. */
+               recwin = roundup2(recwin, 1 << tp->rcv_scale);
                th->th_win = htons((u_short)(recwin >> tp->rcv_scale));
+       }
 
        /*
         * Adjust the RXWIN0SENT flag - indicate that we have advertised

Modified: head/sys/netinet/tcp_stacks/bbr.c
==============================================================================
--- head/sys/netinet/tcp_stacks/bbr.c   Wed Apr 29 21:54:09 2020        
(r360478)
+++ head/sys/netinet/tcp_stacks/bbr.c   Wed Apr 29 22:01:33 2020        
(r360479)
@@ -13756,8 +13756,11 @@ send:
        if (flags & TH_SYN)
                th->th_win = htons((u_short)
                    (min(sbspace(&so->so_rcv), TCP_MAXWIN)));
-       else
+       else {
+               /* Avoid shrinking window with window scaling. */
+               recwin = roundup2(recwin, 1 << tp->rcv_scale);
                th->th_win = htons((u_short)(recwin >> tp->rcv_scale));
+       }
        /*
         * Adjust the RXWIN0SENT flag - indicate that we have advertised a 0
         * window.  This may cause the remote transmitter to stall.  This

Modified: head/sys/netinet/tcp_stacks/rack.c
==============================================================================
--- head/sys/netinet/tcp_stacks/rack.c  Wed Apr 29 21:54:09 2020        
(r360478)
+++ head/sys/netinet/tcp_stacks/rack.c  Wed Apr 29 22:01:33 2020        
(r360479)
@@ -9572,8 +9572,11 @@ send:
        if (flags & TH_SYN)
                th->th_win = htons((u_short)
                    (min(sbspace(&so->so_rcv), TCP_MAXWIN)));
-       else
+       else {
+               /* Avoid shrinking window with window scaling. */
+               recwin = roundup2(recwin, 1 << tp->rcv_scale);
                th->th_win = htons((u_short)(recwin >> tp->rcv_scale));
+       }
        /*
         * Adjust the RXWIN0SENT flag - indicate that we have advertised a 0
         * window.  This may cause the remote transmitter to stall.  This
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to