From nobody Thu Oct 23 11:04:26 2025 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4csjpf2RPCz6DBsq; Thu, 23 Oct 2025 11:04:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4csjpf1lx9z3wjv; Thu, 23 Oct 2025 11:04:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761217466; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qko7jaJwc5vvBULUvA9xpN8Q/w5ON7vOm8mFCFT08zY=; b=epRxK6V3W1FfWmbH8Paka0i667SYREpJfUZoZsz5snD1hmYhPV+qIF3w+/pAiY9HdFmhbb 3R/xwjXL0nOAjrFXzGyL2SutxsgDAw3nV/WFmXpbLVemjCKUc1aQ+OgO/c1Jt4ylFGGOdP WJea8PEAU3rRyt9pWpmLBXyoiSB3MHs4tyt/wd63gPFbEcy4enRWOvjsNaSp8CkPHVoEDz luB/gLmBz23qYVldbMWEiwcFJFHq+JSrz+iEP+3BhauIiq7yFDpPve3r6FYK/ICP/xgmQc aTwBCW0HnW+NaNJfenKy8ZQhZ0tXA1upTvXkEuRvPLs2vJMSCb021xpcjz4QGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761217466; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qko7jaJwc5vvBULUvA9xpN8Q/w5ON7vOm8mFCFT08zY=; b=BjLIbEO7vR9L87Mqk4jQmaeqbMgWjRuoLvt+fDo4RkMicS2y1aeimmea0tQge/vY/wl9NE ea1UrwJc+UN+zx7t95UqIesymgxVbVdlk6y595HLcGJH2NyLP86F4PYe6meqNqOS5ppVkj M1ebrQ1Gmc1OnX4Bci7h1Q0TIhvEkDotAgEFfUIngicRMxA8josUlYjIqGc82vM9suctyL N522N42MsecOj9+Wr7XxHsZK4ydGLkc0H4OqYvATPp5m6a8lTJANCcy2vmy34iLlsDWx8V /s9bG58J7V0LThFzJBO3ZwbacE90+56PovjST74AKvAWjuxL1DpmyCepN0nKgA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1761217466; a=rsa-sha256; cv=none; b=wEaNoLb+Fti/pvw6cgIg2rQdT42QOiszrwGFphGlObgiOFk/spoBRqDyHciR5eOLfz6pIe K9jaXFTqtp+g38bjdkU7p9gBpc2TvHpCTXQSCZESUxCxtBhcj2EItalcdY6g0JkOEBmGmi gI0NvUhOa76EXlr/kOjm9wkTy1/okUulT3yO/uwjjflzWozcXMGdPvBNXU8JMnEH1xqtSr be+ZKHhnMp3pl6EAWnOx84P2iQVuxNahSq6prH3dfv2GyHIMM/PjTyXVJC6nLAf+T4EHyA UkGW+GemgRS/xqkMZ4AdgNbDfA+cC7w8+psrvT5WALQug/M2JEbuzSLKR48P0w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4csjpf17hBz1BYS; Thu, 23 Oct 2025 11:04:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 59NB4Q5Z010895; Thu, 23 Oct 2025 11:04:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 59NB4QAv010892; Thu, 23 Oct 2025 11:04:26 GMT (envelope-from git) Date: Thu, 23 Oct 2025 11:04:26 GMT Message-Id: <202510231104.59NB4QAv010892@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Michael Tuexen Subject: git: 9899843370bb - stable/15 - tcp: cleanup of syncache_expand() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tuexen X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 9899843370bbab8fba614439ea791f2fc889bd80 Auto-Submitted: auto-generated The branch stable/15 has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=9899843370bbab8fba614439ea791f2fc889bd80 commit 9899843370bbab8fba614439ea791f2fc889bd80 Author: Michael Tuexen AuthorDate: 2025-10-17 05:40:02 +0000 Commit: Michael Tuexen CommitDate: 2025-10-23 11:01:13 +0000 tcp: cleanup of syncache_expand() * Consistently free the string after unlocking the sch, if possible. * Remove the failure handling in case of sc != NULL, since this is not possible anymore. * Remove the use of goto and instead return 0 in the three cases. The only change in behavior is that in three out of the four cases, where 0 is returned, *lsop is not set to NULL anymore. So the behavior is now consistent and also documented in a comment. The current in tree callers only look at *lsop, if and only if syncache_expand() returns 1. Reviewed by: Peter Lei Sponsored by: Netflix, Inc. Differential Revision: https://reviews.freebsd.org/D52948 (cherry picked from commit aafdbf83b926519cb47de8f16a1a40c1ef3c84b5) --- sys/netinet/tcp_syncache.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c index f842a5678fa1..be20fb44a820 100644 --- a/sys/netinet/tcp_syncache.c +++ b/sys/netinet/tcp_syncache.c @@ -1046,6 +1046,8 @@ abort: * * On syncache_socket() success the newly created socket * has its underlying inp locked. + * + * *lsop is updated, if and only if 1 is returned. */ int syncache_expand(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, @@ -1094,12 +1096,14 @@ syncache_expand(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, */ SCH_UNLOCK(sch); TCPSTAT_INC(tcps_sc_spurcookie); - if ((s = tcp_log_addrs(inc, th, NULL, NULL))) + if ((s = tcp_log_addrs(inc, th, NULL, NULL))) { log(LOG_DEBUG, "%s; %s: Spurious ACK, " "segment rejected " "(syncookies disabled)\n", s, __func__); - goto failed; + free(s, M_TCPLOG); + } + return (0); } if (sch->sch_last_overflow < time_uptime - SYNCOOKIE_LIFETIME) { @@ -1109,12 +1113,14 @@ syncache_expand(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, */ SCH_UNLOCK(sch); TCPSTAT_INC(tcps_sc_spurcookie); - if ((s = tcp_log_addrs(inc, th, NULL, NULL))) + if ((s = tcp_log_addrs(inc, th, NULL, NULL))) { log(LOG_DEBUG, "%s; %s: Spurious ACK, " "segment rejected " "(no syncache entry)\n", s, __func__); - goto failed; + free(s, M_TCPLOG); + } + return (0); } SCH_UNLOCK(sch); } @@ -1128,11 +1134,13 @@ syncache_expand(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, TCPSTAT_INC(tcps_sc_recvcookie); } else { TCPSTAT_INC(tcps_sc_failcookie); - if ((s = tcp_log_addrs(inc, th, NULL, NULL))) + if ((s = tcp_log_addrs(inc, th, NULL, NULL))) { log(LOG_DEBUG, "%s; %s: Segment failed " "SYNCOOKIE authentication, segment rejected " "(probably spoofed)\n", s, __func__); - goto failed; + free(s, M_TCPLOG); + } + return (0); } #if defined(IPSEC_SUPPORT) || defined(TCP_SIGNATURE) /* If received ACK has MD5 signature, check it. */ @@ -1206,9 +1214,9 @@ syncache_expand(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, "%s; %s: SEG.TSval %u < TS.Recent %u, " "segment dropped\n", s, __func__, to->to_tsval, sc->sc_tsreflect); - free(s, M_TCPLOG); } SCH_UNLOCK(sch); + free(s, M_TCPLOG); return (-1); /* Do not send RST */ } @@ -1225,7 +1233,6 @@ syncache_expand(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, "expected, segment processed normally\n", s, __func__); free(s, M_TCPLOG); - s = NULL; } } @@ -1312,16 +1319,6 @@ syncache_expand(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, if (sc != &scs) syncache_free(sc); return (1); -failed: - if (sc != NULL) { - TCPSTATES_DEC(TCPS_SYN_RECEIVED); - if (sc != &scs) - syncache_free(sc); - } - if (s != NULL) - free(s, M_TCPLOG); - *lsop = NULL; - return (0); } static struct socket *