From nobody Mon Oct 27 22:36:52 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 4cwSzm5mzbz6FjVv; Mon, 27 Oct 2025 22:36:52 +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 4cwSzm5Fzrz447b; Mon, 27 Oct 2025 22:36:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761604612; 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=zaw/n1eeOeFhcC0L2XKsFd1obcViormDJ/pOYUHrtMw=; b=BKaLuE+/zfP3rlYpcE8wGOmOmwAUj/MmS7TWnQhMhIU2z02GlkJIMgISqwFtPgDhHMIQIB VaiJmNhEPfKYbk1gn3Njkui3VJk1W78UNq6YzU57etlM/yOgDfSqcql7/1xkr/sBRfYlZW aAaJpvT3K7fRXtQYf0Y9g4cO4P1uljyujNWXGOGluFGpTGs6Zj6UKItljivfZo6e2DLcKL 4fJs4Qwle8nWqKjjZkiRGliYqpcWtoAAUn5TlzsW1VEcWSAHty3sW8DaYuecN7aOICPi14 NFcuzaErZtAduSJJp0rzO8Cdts7qJVH4ZUrSuyNxquoGfSaP2kNo19Seo1grfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761604612; 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=zaw/n1eeOeFhcC0L2XKsFd1obcViormDJ/pOYUHrtMw=; b=hXlYoeQ+zkS60ldjxkfTYd0Bt0MWbfk/68frkVzyJNDwQCLypPrcHJaRMB3rO0hAzIITSK Hpj2IJbGUFzObCFBEglMjKXk83aHGDcwjOCvIUZzGL+EtsX6IKp7UPxcALEuYwO6IWF6Yb +wKc3oDGNjFV8e4w8EkdLZU/ADunkllNPxRubKaUdIdnTzdLGSh+CqI9DZzlnzwj5Ra1E+ UzZ7mSy9XakjTqaove9n2/eDcvOGjE+VV7aD65VuYBYIp/Xn++Au8rEVXEeVE00Fbh93+g eM+UsjZGXrK2B36yJhiVqI2GrbFal7T0Y49ENbAdPinS3Xeh3groM70hYf9wwA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1761604612; a=rsa-sha256; cv=none; b=jyiaEydeXmmCOC+8hX+P+kUuXdbudV6NspfsTy/6sFnHF7ltvymRXW8c78uj79PofWJVWj u87u2ny5EKHRO7wm07vJuEv31e4xJUOsBZPOYO9/2X8tTJUi3NLJ1nc7COgUcN3zFeYCvl Hn4VWsORMLiFaH3uPquMKP3pkiwro0PFh+ElCbAYaWN2VP+y+581p1Tp2jOhnG+ygH3ev0 uCaMI1pgx421QFvZYQSuaxMIc8GP4tls2O1CVp7JY0/1OxPzIy1y1xhF6jTBg567OaopF/ JBny+xqhYcaEnFmNySXbad7A9mVZkBrMb/lf0quI5ei6gTxgJzDEKLliXcKQdg== 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 4cwSzm4rzzz7ZH; Mon, 27 Oct 2025 22:36:52 +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 59RMaqSw097682; Mon, 27 Oct 2025 22:36:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 59RMaqVp097679; Mon, 27 Oct 2025 22:36:52 GMT (envelope-from git) Date: Mon, 27 Oct 2025 22:36:52 GMT Message-Id: <202510272236.59RMaqVp097679@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: 44cb1e857f04 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 44cb1e857f048d2326bdc1a032ccd2c04d2bcdc9 Auto-Submitted: auto-generated The branch main has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=44cb1e857f048d2326bdc1a032ccd2c04d2bcdc9 commit 44cb1e857f048d2326bdc1a032ccd2c04d2bcdc9 Author: Michael Tuexen AuthorDate: 2025-10-27 22:28:59 +0000 Commit: Michael Tuexen CommitDate: 2025-10-27 22:28:59 +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") MFC after: 3 days Sponsored by: Netflix, Inc. Differential Revision: https://reviews.freebsd.org/D53380 --- 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 3cb538f7054d..3a7755e9f09e 100644 --- a/sys/netinet/tcp_syncache.c +++ b/sys/netinet/tcp_syncache.c @@ -1380,6 +1380,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; @@ -1408,6 +1409,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) { @@ -1636,16 +1638,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; @@ -1783,6 +1785,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);