From nobody Thu Oct 31 13:56:13 2024 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 4XfQWd2cZmz5bl6y; Thu, 31 Oct 2024 13:56:13 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XfQWd23xpz3xyH; Thu, 31 Oct 2024 13:56:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730382973; 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=tR9jt5U6I7vSkHokU85APh1Y3qyinpi+Y6oL9/+pnkY=; b=jARC9VV7Mp02WddmwfgwxF5zB34hUtiYd1pUiRHBSpWuyeoSRrNH9Oa5xJSgTLr5QKeQQK YcODY7UVXCYZKboZB3hx0yRyfEqsjDUWO6C6jypGFhBb9OAcE7OH5O7wVvraBx0CpfQIBS Fa9tIfJGPiXOkams6cGgS7ATxpgG8FbuQTbHlZqaEtQxZ0PSUwGEhRUHgUFv6U82W6zlh3 R5EZQ+CuwilWN+VQZJdJ9tPpvkLdPrxOAST8gfhRRlR0GfC+UKZ/+zD9PZjCMDNEx1R9zm 4SibtQI1GZ66obGEfTAUZ8LzfyvqEVeuDhqxsraL1kX2GNPADOdWpttjnewoOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730382973; 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=tR9jt5U6I7vSkHokU85APh1Y3qyinpi+Y6oL9/+pnkY=; b=Qy5pBzN/5fZ3YDGzeZFor1LYdGccmIuyi2L6OixxSttTDxf95vJ3iBE/HFmyJdSGGj33ks MHXmyHMrSZk9kCCDkUPhtordR+koha/XL9kHmam2SUzlBJSXiQ1cn7MlerNRFzwUQh18Jj DQkA0UlGvpFef5cB1x37MpArT8q6nhaPADLgZ1sxVjKIpOHwTWlxRRC8npvWtAg8iA2ZKe RlIPLhM04MHdsEbG1A6vFuCpdADH8bJmqeM0ENk3pA9z26qtusaoC5lZUG1ELEboCBBoKC 64B/9tnxqiIUctUMeUIFCsn29kG2mHg7KYZEK2y8AnEHdmY6P3GbpA5uGdiIyg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730382973; a=rsa-sha256; cv=none; b=f0dtbt6JnWm9zJZqoLxYRCrTKP9Fn4IvSewxlOGcD0MpQIgZ3nBRuN1KUyqe9BtekA8dmv l67PjSxFpPRUOUJ+liFpVVeULApIH7062k1p44+3O+AedBAeRNF2QOtOAyfRQbbsC7LhL1 p8s6Yk/6vF67iTywyu/dUcud/+iUeE/CYLnasA3/EWseehMjCoD8tpXDfdKId4XHLQ3j9G n6uK/HXjjlg2Z+29bJ4URKJz0ueVYjQ5ZZbMb/pI2g1QjyyABdbcgujKS7VpJbrHJ8QOzd aZIUb0e7vnAwNwM7caP8pa8j4B0Nf/i5/PvhOZIJDKcV6p5RYX5SWVL1bxal9w== 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 4XfQWd1MQ1zfGg; Thu, 31 Oct 2024 13:56:13 +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 49VDuDFx028800; Thu, 31 Oct 2024 13:56:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49VDuDGX028797; Thu, 31 Oct 2024 13:56:13 GMT (envelope-from git) Date: Thu, 31 Oct 2024 13:56:13 GMT Message-Id: <202410311356.49VDuDGX028797@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: 00c3c39fcc4c - stable/14 - tcp: improve ref count handling when processing SYN 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: 00c3c39fcc4ccdbc2b83ed0f0f2838863856b795 Auto-Submitted: auto-generated The branch stable/14 has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=00c3c39fcc4ccdbc2b83ed0f0f2838863856b795 commit 00c3c39fcc4ccdbc2b83ed0f0f2838863856b795 Author: Michael Tuexen AuthorDate: 2024-09-28 20:06:41 +0000 Commit: Michael Tuexen CommitDate: 2024-10-31 11:34:33 +0000 tcp: improve ref count handling when processing SYN Don't leak a reference count for so->so_cred when processing an incoming SYN segment with an on-stack syncache entry and the sysctl variable net.inet.tcp.syncache.see_other is false. Reviewed by: cc, markj, rscheff Sponsored by: Netflix, Inc. Pull Request: https://reviews.freebsd.org/D46793 (cherry picked from commit cbc9438f0505bd971e9eba635afdae38a267d76e) --- sys/netinet/tcp_syncache.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c index fa64d2d79c3b..0f7e7359679f 100644 --- a/sys/netinet/tcp_syncache.c +++ b/sys/netinet/tcp_syncache.c @@ -1385,7 +1385,6 @@ syncache_add(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, struct label *maclabel = NULL; #endif struct syncache scs; - struct ucred *cred; uint64_t tfo_response_cookie; unsigned int *tfo_pending = NULL; int tfo_cookie_valid = 0; @@ -1402,7 +1401,6 @@ 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) { @@ -1633,9 +1631,21 @@ skip_alloc: #ifdef MAC sc->sc_label = maclabel; #endif - sc->sc_cred = cred; + /* + * 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: + * - 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 + sc->sc_cred = NULL; sc->sc_port = port; - cred = NULL; sc->sc_ipopts = ipopts; bcopy(inc, &sc->sc_inc, sizeof(struct in_conninfo)); sc->sc_ip_tos = ip_tos; @@ -1771,8 +1781,6 @@ 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);