From nobody Thu Oct 30 04:23:31 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 4cxrZq4YR0z6Djcn; Thu, 30 Oct 2025 04:23:31 +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 4cxrZq3yKsz3FXt; Thu, 30 Oct 2025 04:23:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761798211; 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=7LoRD5pM483uMVneL49EASEI81IVAF7m3WJNVYuxbSM=; b=og71Qp4tob4rQVOPFEC+PNDu2iwR3yZGKRk9QeqkRpmWkLCXGulsJEbvrOoeUwRBn6qJlJ vgQ2f8swMn1WGdgwhw1r1+y4npLVDeinIUtmInjiNOqw1RKTAKHLMdCfye8PcIT0KoshoU Vg139S12ebRiMv29AbGxWAWUxa6Nu5McSKJnLfDRaa1p+qqN35gFwjLxZGoGfDMBhr7yl5 oV/3jpHrBttHnxb6an7+AhVLFmpnspL0ib1F4FSvVOGQqKrsK9jz8d55nqahwUUNAYgGB+ /28xCr5cSMFWZjjF8yyhfod4NAit4Oe90aQWC2dmg3OxtWNxr04jFf0i3A4/ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761798211; 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=7LoRD5pM483uMVneL49EASEI81IVAF7m3WJNVYuxbSM=; b=CqfxwhZiW4gKcX1+YVAw91Pwje4wgLLfRvpfxOSaDSYdZH2y77dbSPIvxFRfslEgqWc8u7 z6ReGIz/4DG3NpMupReM59NT/J5yDdYVrBIqThLFZjcGaRdMh9qacup2q6zcr79ccAxkK8 F007/uDoufH3JIh8i2axIEsxQQjnIpUTvu47cc5gaet4g0/jXQLiT89naxtxpuosgVXYoE E0mdPzDn2R1JH2NmOBgcMepps7cBqHP24kNJ3arF74Ifd8FKe11PGNRFW3onF9KReuCbZw hEcfdofxHQ+ni9/FZEV4CE+guPunsf2AQ5816bjCLHPO/GkfKnF3wuanecwAXQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1761798211; a=rsa-sha256; cv=none; b=QkmX3ir8s2I1Dhv41NW2Ybz1sUcRJv7U/Na4bBd1RIOYm/kMuTg6Sf51h37/STJpQCh171 QSwWe42x1L6J1p32L5iXPB9VLEPhUjRsBda6XL9Eo+wFaeFfqCVIK+VFgUzYK05InFAwHD v8OBTygB6TFHezJkopwm93EBpS7vPgALMoyH0nRoIaECrrAWL9DRFczYuS/HOfuN7t4Nrr XmIEOwFqqjP7zwXyFR0PwT14hdzaXFQPpSJICgR0dGdOtzYqLq4r04BZdsYxcSkl1SALF6 jecnCqCMb17HjpziiCEjqekVnOr48URitt7RpqRtTbqwAQtc+man9aXBajVvjA== 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 4cxrZq3Rq5z16c3; Thu, 30 Oct 2025 04:23:31 +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 59U4NV55084040; Thu, 30 Oct 2025 04:23:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 59U4NVgD084037; Thu, 30 Oct 2025 04:23:31 GMT (envelope-from git) Date: Thu, 30 Oct 2025 04:23:31 GMT Message-Id: <202510300423.59U4NVgD084037@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Colin Percival Subject: git: 71f94c1e2c8f - releng/15.0 - tcp: improve credential handling in syncache 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: cperciva X-Git-Repository: src X-Git-Refname: refs/heads/releng/15.0 X-Git-Reftype: branch X-Git-Commit: 71f94c1e2c8f68935fb81db168099d6f97ff220b Auto-Submitted: auto-generated The branch releng/15.0 has been updated by cperciva: URL: https://cgit.FreeBSD.org/src/commit/?id=71f94c1e2c8f68935fb81db168099d6f97ff220b commit 71f94c1e2c8f68935fb81db168099d6f97ff220b Author: Michael Tuexen AuthorDate: 2025-10-27 22:28:59 +0000 Commit: Colin Percival CommitDate: 2025-10-30 04:22:06 +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. Approved by: re (cperciva) 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) (cherry picked from commit 9611bf2fed71ca62161249630f98e7eac06eff6b) --- 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 f842a5678fa1..57aeb86f6351 100644 --- a/sys/netinet/tcp_syncache.c +++ b/sys/netinet/tcp_syncache.c @@ -1383,6 +1383,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; @@ -1411,6 +1412,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) { @@ -1639,16 +1641,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; @@ -1786,6 +1788,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);