From nobody Thu Oct 23 11:18:18 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 4csk6f4NxCz6DDMB; Thu, 23 Oct 2025 11:18:18 +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 4csk6f3rSYz41Zc; Thu, 23 Oct 2025 11:18:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761218298; 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=OOMnw0DLqKDmrn9bkMzAEugQl8dcQalGZ4vulXAqRyA=; b=LyPeXBgnIN/+35K1NSYHjIQInzL8pCaI1GHXnHUOhEMw6AtHEByQzyWVaMu7zjeKeEtFtQ 539CUs6IWeMqgLgYwSf8Jj7+rZYZdqqQgBXvBLzAD3m6Xse9ZIo5l0y6zlRrFFDOVF0JpC kj6iDNynRVbod5FvOiEax5q/+YSvXxBNK7KODmfyeHdXB8Dr8cxbYAs2g7fACbJnVAG+H4 njEg03gq5iLeDWbb+nf2mrGq3Sn8RgCrjOBTT+RP2g9Bwv1QR7SeLyzi3uyfraE3UhX1hr c2PlomOVO1Del/HGr/VRHvM/z7fYRAZUYQRkwx52LGq/cqcQgdNSGaoC5nBC/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761218298; 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=OOMnw0DLqKDmrn9bkMzAEugQl8dcQalGZ4vulXAqRyA=; b=Qm2DFdNyjYpQ3RDg+/QXAm7RIuGw/71W2J2P0MKZneF45/457XpdAlkpD/n24zMpVq/cCq ZuwW/zbXufhuk+fDuBsFnQBJfuIH1Dpi9VUovSwJj6WPl9LMp2L3b+1BvE81ofb0U53yn4 Y2nCT7cbaRvjowc68XAolqST+uAAlNkVPp5FxkTxLN6xnHvwXKtRqhtKcd2HN1G1qgWB2/ fv3N6rogA69EEZE4ZwzSOqYX+WkJ398QEi0+5X2ZZBpV5N7iXokHT0DuwWPExKOyHRJ63U qp7F/qAP3WS4Zo/k9gsJFuozGGMXafju6DH/4w8/Vbu19xwSM+Qkdj9gr7TRwA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1761218298; a=rsa-sha256; cv=none; b=JyyezKmb3QlvmIGFu/pqNCm1svvx0DdPFLBybKiItMj3O0ia09yPVy6u27S6l82afEsVC9 bviaN/BYh20PnIKNyFLoeX+46Yv7baQzCAm4Ku3W6JX7a2JWzVzUi/ySUY1xTaa3CiDsIj cdJfSQF0q4dGOYUTqkXVw/V7JLozwhCUSyGUtBeAx3/RoF9vLGVBrpiYejf3P/jv2Q47+b G+qWCSDqnFEAV4Bjs65kRlHeXzQZbe5WxDyQH5Wo0fnpJFrFvxpRegC2V1OTyF2h62oUo2 yI5CgYtHD0Vv1kJv26YW5joh9T0L11vmADyEJiBymxjGMeRAHYk+v/t+b/Z7hA== 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 4csk6f3QvQz1BdW; Thu, 23 Oct 2025 11:18:18 +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 59NBII59031798; Thu, 23 Oct 2025 11:18:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 59NBIIt6031795; Thu, 23 Oct 2025 11:18:18 GMT (envelope-from git) Date: Thu, 23 Oct 2025 11:18:18 GMT Message-Id: <202510231118.59NBIIt6031795@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: 6626f4e1a8f7 - stable/14 - 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/14 X-Git-Reftype: branch X-Git-Commit: 6626f4e1a8f779cf454cea899df1220a08c833d6 Auto-Submitted: auto-generated The branch stable/14 has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=6626f4e1a8f779cf454cea899df1220a08c833d6 commit 6626f4e1a8f779cf454cea899df1220a08c833d6 Author: Michael Tuexen AuthorDate: 2025-10-17 05:40:02 +0000 Commit: Michael Tuexen CommitDate: 2025-10-23 11:17:51 +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 1c585378dc5b..077c3a5f6ef3 100644 --- a/sys/netinet/tcp_syncache.c +++ b/sys/netinet/tcp_syncache.c @@ -1056,6 +1056,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, @@ -1103,12 +1105,14 @@ syncache_expand(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, * a valid syncookie. */ SCH_UNLOCK(sch); - 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) { @@ -1117,12 +1121,14 @@ syncache_expand(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, * don't even check for a valid syncookie. */ SCH_UNLOCK(sch); - 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); } @@ -1135,11 +1141,13 @@ syncache_expand(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, sc = &scs; TCPSTAT_INC(tcps_sc_recvcookie); } else { - 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. */ @@ -1213,9 +1221,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 */ } @@ -1232,7 +1240,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; } } @@ -1319,16 +1326,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 *