From nobody Fri Oct 17 05:45:10 2025 X-Original-To: dev-commits-src-main@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 4cnv1252xlz6Cfvp; Fri, 17 Oct 2025 05:45:10 +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 4cnv124WFvz3SGD; Fri, 17 Oct 2025 05:45:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1760679910; 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=c5Hkys2H632TokEjVnl9AEn8ZEw9sR34+WEks+RZN7Q=; b=OEDZLCzpLzvXT+UvkzIoCjWOJ3uXk6Fg/1qMAb7MwKLl+z7xYdDBdUqlqqgK2MKP7bwaGW T2CtH+Xv4IKrDp1zYyJ1+NkIpQVes7sbqVj5hKmxvL/eVXSSxSqSMOlx53YgXK7kZsZuaD iDwslImi5INWmL6rr/MMVlgS3X9EX9Kcjbiwa/kqlt6koZCTTcbmH67C365YN0O50sZcpL ti1YlguweDZvSuieip5yExbVjiLbUjmjFG0ENiguaNEBS39AZHF+9MBOxRS44e4O8myl1P DyjYiuKHGacq8VmLvW2G6a1JpImY0qUcGt39jNehcu+buvypXgmDRwuFb/jHLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1760679910; 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=c5Hkys2H632TokEjVnl9AEn8ZEw9sR34+WEks+RZN7Q=; b=jMTzKsFwlBqR0eZlBN98CvIC2itJy+jMJMT3cQWAl3WHVK6Me0PjPgRPMkun/GdCULYqI9 QgdLfpDR8FWjoy0VlvE8niGu7nKbPMGnyGNKrOyWgIbgJOw3EcT+41TjuTx1/4DgHd0DQL 0pF4fFPrAOTmozDgEi4vw5EhRYR7L9BGC96Q7eQJ/ejKKhrBcADdprp1IX5h75OCRQPz5F sdW9rq8XLDw1CCyp08YGvKPafGMhxVbQ82wTx7tps0/LtmSczSpeYjWrdNtEmyTRoU6KBj 1EQhCJKaaIgDKu+fySPzvzRL31T3RQWG6LMCGjG9WPW72L0j5HJTRf3yiplRVw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1760679910; a=rsa-sha256; cv=none; b=doLG4E75FpKWTwQsBCJRkxc7AXHnpqbxcS+oNKtpDUOdZKEO5we11Ycpbdd+E3McRlbcx5 nziSVNgKWD8jW9KH2kbBzBKRLGSmhxhGGaXBHgCc0bOZO46pB8Nz/Iu5FYwa+zCvGn+XtZ cYSiWT9pxXkc5ciWOeqq1uCVP39ZzQh/XUARpghh6IDOUNegAmnJ0iLAgQmYuauMO22iRQ Yz3wcUwmy9CLRb6zD9nyubxevaY1/qt8obKeDA6NJfA/PjKvpOKbh7TpTYedvadwfiy7t/ hMfZ1ZimJCStfT6X7EaDz8q5xOWj4++jLBiFyrQ074oIz9bh0X+vCDXkWYP/zQ== 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 4cnv123t2Bzj61; Fri, 17 Oct 2025 05:45:10 +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 59H5jAh5009503; Fri, 17 Oct 2025 05:45:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 59H5jA4b009500; Fri, 17 Oct 2025 05:45:10 GMT (envelope-from git) Date: Fri, 17 Oct 2025 05:45:10 GMT Message-Id: <202510170545.59H5jA4b009500@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Michael Tuexen Subject: git: aafdbf83b926 - main - tcp: cleanup of syncache_expand() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: aafdbf83b926519cb47de8f16a1a40c1ef3c84b5 Auto-Submitted: auto-generated The branch main has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=aafdbf83b926519cb47de8f16a1a40c1ef3c84b5 commit aafdbf83b926519cb47de8f16a1a40c1ef3c84b5 Author: Michael Tuexen AuthorDate: 2025-10-17 05:40:02 +0000 Commit: Michael Tuexen CommitDate: 2025-10-17 05:40:02 +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 MFC after: 3 days Sponsored by: Netflix, Inc. Differential Revision: https://reviews.freebsd.org/D52948 --- 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 *