tcp: fix counter leak for SYN_RCVD state when syncache_socket() fails

The SYN_RCVD state count is tricky here due to default code path and TFO
being so different.  In the default case the count is incremented when a
syncache entry is added to the the database in syncache_insert().  Later
when connection transitions from syncache entry to a socket in
syncache_expand(), this counter is inherited by the tcpcb.  If socket or
tcpcb allocation failed in syncache_socket() failed the syncache_expand()
is responsible for decrement.  In the TFO case the syncache entry is not
inserted into database and count of SYN_RCVD is first incremented in the
syncache_tfo_expand() after successful socket allocation.  Thus, inside
syncache_socket() we can't tell whether we need to decrement in a case of
a failure or not.  The caller is responsible for this book keeping.

Fixes:	07285bb4c2
Differential revision:	https://reviews.freebsd.org/D37610
This commit is contained in:
Gleb Smirnoff committed 2022-12-13 19:31:05 -08:00
1 parent 54d65fdd56
commit 5050df3f4a
1 file changed
+3 -2
+3 -2
View File
@@ -1313,9 +1313,10 @@ syncache_expand(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th,
*lsop = syncache_socket(sc, *lsop, m);
if (*lsop == NULL)
if (__predict_false(*lsop == NULL)) {
TCPSTAT_INC(tcps_sc_aborted);
else
TCPSTATES_DEC(TCPS_SYN_RECEIVED);
} else
TCPSTAT_INC(tcps_sc_completed);
/* how do we find the inp for the new socket? */