The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=e65b7079db12afb1aa61be4f1c666b162984a95e
commit e65b7079db12afb1aa61be4f1c666b162984a95e Author: Gleb Smirnoff <[email protected]> AuthorDate: 2026-10-02 02:53:31 +0000 Commit: Gleb Smirnoff <[email protected]> CommitDate: 2026-10-02 02:53:31 +0000 tcp: use SB_AUTOSIZE flag to tell if socket buffer was set The check against V_tcp_sendspace is not a correct one, as a buffer may grow larger than the initial value. The conjunction was always false up until 587c6c121504, and only after it the bug surfaced. If we already grow our buffer past the value stored in the hostcache, prefer our value. Reviewed by: tuexen Differential Revision: https://reviews.freebsd.org/D60105 --- sys/netinet/tcp_input.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index e79f652bcb54..e74d533f7baa 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -3888,18 +3888,15 @@ tcp_mss(struct tcpcb *tp, int offer) mss = tp->t_maxseg; /* - * If there's a pipesize, change the socket buffer to that size, - * don't change if sb_hiwat is different than default (then it - * has been changed on purpose with setsockopt). + * If there's a pipesize, change the socket buffer to that size, unless + * it has been set by a setsockopt(2). * Make the socket buffers an integral number of mss units; * if the mss is larger than the socket buffer, decrease the mss. */ so = inp->inp_socket; SOCK_SENDBUF_LOCK(so); - if ((so->so_snd.sb_hiwat == V_tcp_sendspace) && metrics.hc_sendpipe) - bufsize = metrics.hc_sendpipe; - else - bufsize = so->so_snd.sb_hiwat; + bufsize = (so->so_snd.sb_flags & SB_AUTOSIZE) ? + max(metrics.hc_sendpipe, so->so_snd.sb_hiwat) : so->so_snd.sb_hiwat; if (bufsize < mss) mss = bufsize; else { @@ -3931,10 +3928,8 @@ tcp_mss(struct tcpcb *tp, int offer) } SOCK_RECVBUF_LOCK(so); - if ((so->so_rcv.sb_hiwat == V_tcp_recvspace) && metrics.hc_recvpipe) - bufsize = metrics.hc_recvpipe; - else - bufsize = so->so_rcv.sb_hiwat; + bufsize = (so->so_rcv.sb_flags & SB_AUTOSIZE) ? + max(metrics.hc_recvpipe, so->so_rcv.sb_hiwat) : so->so_rcv.sb_hiwat; if (bufsize > mss) { bufsize = roundup(bufsize, mss); if (bufsize > sb_max)
