From nobody Fri Oct 31 19:14:44 2025 X-Original-To: dev-commits-src-all@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 4cyrJh6zY7z6Dp16; Fri, 31 Oct 2025 19:14:44 +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 4cyrJh6Fqdz4GbF; Fri, 31 Oct 2025 19:14:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761938084; 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=LuGja1m7Pw5Ywl/+RcBHkRZ2N4dzNPOeicbA0QOMUmo=; b=gHuVYzmQL3T913LeMj0ov+KckiAuMYfI0bPSXKwv4kGYuhqdbbWnjTwo/P9WjBFewl1i+2 f1vnFf2U+u3temd758sTdqwlHrR5szJgqjLFsrBxyOZsk/YEkQjUBCGo8MIRlY243fwpaO ceKq30XmhORE6/Wx2+mxDjbMlm4JmeNrhs9SsTp5qIeigpETAsIV7D7s2VB6HF8SBRUent SYHEq/AkkIERBMNQtQJaJThUuqtqEuDZ05M/bsf/Vgo5WKUv10W4HXB3NV94HQr0KzC6Hs Yn5rMWAF5auCgCHCILbpicbQopU2yIucq+HroF6vQr4Bu8U5OJpSQjTEnXWDNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761938084; 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=LuGja1m7Pw5Ywl/+RcBHkRZ2N4dzNPOeicbA0QOMUmo=; b=n9riZoYnZDgg0oe6hplZgSCGgozD9xRV1zTyPF2xx1rmE7RXkg/7rHAHXWBw0Fqxx/gKRo I0ln17r1+R4HEsyL5Tm6EEoehVEqMPnwkDGmproaoyTOcLfjcE1tkUs8Uz6bdLbc2sIVV1 SHjkoxtQBVT1vShaO7CRxLqi916yY2svGW4uSOvsnFn9RUzIkSpqOQ9iO5oUh63Msrzl4M +8q0jJ8L1ms14BZCWgCGtcahFaDMk9Bck052sLOFsv/+GFl3fY7xI7e0qysQHzROLN2HZl MhsYktfim1CSjEp6A1GqaTHBuxDW/ND0x2z5FvExU0uYpnAb56H9vJNjmvrEDA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1761938084; a=rsa-sha256; cv=none; b=N3jWJ5ynDiGd/DwyL2JLdC+qVxKqS3P0L/lRDN+/p0BKD5Cu6cteU0lXJFNvhmc2Spfw38 OeIZTp2W5bcn9GbhD+V0qqQdAmuVBx0URcVHsc7wg0zuWxCxcDc46/cpR/Khzu62DCi9Tb ceyOZijGEZxyCdUAZNY7Q1dIjMKEqzEInfAzXN2W6+H4Dm4JrAKM+L2XJC2Ib7Gu75Sdbj ZNxd/sJ9OHFdrh1y9tXwCagBvcYQoWCRx3WzUFZH88x/9v+INdtCJwa2+fwIxmfH9qcQI6 zdjN+wg0K4peU5c+JaaTmOHj+bgsxQvO6hdBoAzDRoxAhV8kvdlCi60LjJE7xA== 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 4cyrJh5dZkz1L2p; Fri, 31 Oct 2025 19:14:44 +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 59VJEiqD080346; Fri, 31 Oct 2025 19:14:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 59VJEilO080343; Fri, 31 Oct 2025 19:14:44 GMT (envelope-from git) Date: Fri, 31 Oct 2025 19:14:44 GMT Message-Id: <202510311914.59VJEilO080343@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: 4b555b56edfd - stable/14 - tcp: improve credential handling in syncache List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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: 4b555b56edfdd714df9010bbbb630d3d3a32f6d0 Auto-Submitted: auto-generated The branch stable/14 has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=4b555b56edfdd714df9010bbbb630d3d3a32f6d0 commit 4b555b56edfdd714df9010bbbb630d3d3a32f6d0 Author: Michael Tuexen AuthorDate: 2025-10-27 22:28:59 +0000 Commit: Michael Tuexen CommitDate: 2025-10-31 14:14:10 +0000 tcp: improve credential handling in syncache When adding a syncache entry, take a reference count of the credentials while the inp is still locked. Thanks to markj@ for providing a hint regarding the root cause. Reported by: David Marker Reviewed by: glebius Tested by: David Marker Fixes: cbc9438f0505 ("tcp: improve ref count handling when processing SYN") Sponsored by: Netflix, Inc. Differential Revision: https://reviews.freebsd.org/D53380 (cherry picked from commit 44cb1e857f048d2326bdc1a032ccd2c04d2bcdc9) --- sys/netinet/tcp_syncache.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c index f1402734103a..713f6a35ad45 100644 --- a/sys/netinet/tcp_syncache.c +++ b/sys/netinet/tcp_syncache.c @@ -1387,6 +1387,7 @@ syncache_add(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, struct tcpcb *tp; struct socket *rv = NULL; struct syncache *sc = NULL; + struct ucred *cred; struct syncache_head *sch; struct mbuf *ipopts = NULL; u_int ltflags; @@ -1415,6 +1416,7 @@ syncache_add(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, */ KASSERT(SOLISTENING(so), ("%s: %p not listening", __func__, so)); tp = sototcpcb(so); + cred = V_tcp_syncache.see_other ? NULL : crhold(so->so_cred); #ifdef INET6 if (inc->inc_flags & INC_ISIPV6) { @@ -1643,16 +1645,16 @@ syncache_add(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, /* * sc_cred is only used in syncache_pcblist() to list TCP endpoints in * TCPS_SYN_RECEIVED state when V_tcp_syncache.see_other is false. - * Therefore, store the credentials and take a reference count only - * when needed: + * Therefore, store the credentials only when needed: * - sc is allocated from the zone and not using the on stack instance. * - the sysctl variable net.inet.tcp.syncache.see_other is false. * The reference count is decremented when a zone allocated sc is * freed in syncache_free(). */ - if (sc != &scs && !V_tcp_syncache.see_other) - sc->sc_cred = crhold(so->so_cred); - else + if (sc != &scs && !V_tcp_syncache.see_other) { + sc->sc_cred = cred; + cred = NULL; + } else sc->sc_cred = NULL; sc->sc_port = port; sc->sc_ipopts = ipopts; @@ -1790,6 +1792,8 @@ donenoprobe: tcp_fastopen_decrement_counter(tfo_pending); tfo_expanded: + if (cred != NULL) + crfree(cred); if (sc == NULL || sc == &scs) { #ifdef MAC mac_syncache_destroy(&maclabel);