From nobody Thu Jan 27 15:42:54 2022 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 3041B197AB6B; Thu, 27 Jan 2022 15:42:55 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Jl4bz0vDBz4t8M; Thu, 27 Jan 2022 15:42:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643298175; 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=+CVTGVg1bbG34b0Jyxy2wA8ZakxOGVCnlt7kINX9/DI=; b=SkPPAhTqy+WzkZbtEO9fjLiBYN83r6aHGVniU1e4tCfL/DP2Oj6VcoURsztFBS5TNTKqUX 5W/YnyeIIKknZypP+4Zq5lurgFNl6+Eq4fPtVDHnpfYZROB8HwaJElQNVk85rvBmn+kwg1 tiSz97Id/50V0+hPNiDXpQJG5zrrnejUAIUwZrsuP7KrxHEHhm9QM/XzpzZrfiiCWMnE9W m0z47cOJup7eP8z/abgUz1oEIFjajTPdUIR51Kqpx/rI3CaxgT4Szm3Euo5udGkb4JdVaf OjM7wgtj+0hBfgUFawO4CsgQ7t5D1RTq8f243z5VvnpTwNWGNRAeYqBhLe79zg== 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 F364619791; Thu, 27 Jan 2022 15:42:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20RFgsP6045904; Thu, 27 Jan 2022 15:42:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20RFgsB3045903; Thu, 27 Jan 2022 15:42:54 GMT (envelope-from git) Date: Thu, 27 Jan 2022 15:42:54 GMT Message-Id: <202201271542.20RFgsB3045903@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Gallatin Subject: git: 8a7404b2aeeb - main - tcp: fix leaks in tcp_chg_pacing_rate error paths 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: gallatin X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8a7404b2aeeb6345bd82c13c432e56d8cbfba869 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643298175; 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=+CVTGVg1bbG34b0Jyxy2wA8ZakxOGVCnlt7kINX9/DI=; b=fyJbPmfj6sKqiNTA1VjIMnRyblKOUoWH74Y+6wGW0G43Yi4nqtnoKlh82RrBZ1GE3DVknf ppuWYG7KJxt//14fpl3emidD0GNacz8ABEGVHdyRIO75wwKGMvTUol/9Rc1QItdljFMVMN hR3jvi1uwZzGQi29eZpo51+aljOxGHE2zLx3PE+92oclDIKy3V981iCIwz7FR1l+gTGQUh Hk9CdR0FfineVMwOwqqZO6L3fpzcX/MVi9cZE7EepqFNEP5McNpASqxzoW0RUZpfOtesHK buW7xA3gpYzc9TQ5KBktyyGgcQvKTTVKW+hZ3CSUDXcs7Ek5n3luF4y9c7rJdQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643298175; a=rsa-sha256; cv=none; b=dY6t1W/GcGAdLaWAN0wNRAGZX5oUwddBQvRElR7Urp4VpUWDWjN3CKswSjs4nB5p0qxE/q QPkMM3MuwOz80o30TfAfSVPQexAKdVWWYdXpLQbNKRlAuULMOZkmHJwtf8zDvPY+17CY1x Q2y+RLbLcWDDUIhQ1FQ2Pge9u3QNcSC4lnuWrTgBtJTruFwrTujXB1ZGQWoyS5vNKc7nnk ux185j8JGhcpBQYnQEbHOKKQyDKVtm/fEzG9Fo03OSfswKFR+mWk4rSDa3WQHsR/iNiqFz dI+F7pkfQEGrG09AQACszqaF8lBtLNGDeQ22Wc7gxdhtRahZTQ1QHuf+E0iztA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by gallatin: URL: https://cgit.FreeBSD.org/src/commit/?id=8a7404b2aeeb6345bd82c13c432e56d8cbfba869 commit 8a7404b2aeeb6345bd82c13c432e56d8cbfba869 Author: Andrew Gallatin AuthorDate: 2022-01-27 15:35:03 +0000 Commit: Andrew Gallatin CommitDate: 2022-01-27 15:35:03 +0000 tcp: fix leaks in tcp_chg_pacing_rate error paths tcp_chg_pacing_rate() is expected to release the hw rate limit table, but failed to do so in several error cases, leading to ever increasing counts of flows using the rate. This patch was mostly done by rrs Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D34058 Reviewed by: hselasky, rrs, jhb (inital version, outside of Differential) --- sys/netinet/tcp_ratelimit.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sys/netinet/tcp_ratelimit.c b/sys/netinet/tcp_ratelimit.c index 96a38b6afd54..2f36cea4faed 100644 --- a/sys/netinet/tcp_ratelimit.c +++ b/sys/netinet/tcp_ratelimit.c @@ -1411,6 +1411,7 @@ tcp_chg_pacing_rate(const struct tcp_hwrate_limit_table *crte, * tags if it didn't allocate one when an * existing rate was present, so ignore. */ + tcp_rel_pacing_rate(crte, tp); if (error) *error = EOPNOTSUPP; return (NULL); @@ -1419,6 +1420,7 @@ tcp_chg_pacing_rate(const struct tcp_hwrate_limit_table *crte, #endif if (tp->t_inpcb->inp_snd_tag == NULL) { /* Wrong interface */ + tcp_rel_pacing_rate(crte, tp); if (error) *error = EINVAL; return (NULL); @@ -1457,10 +1459,29 @@ tcp_chg_pacing_rate(const struct tcp_hwrate_limit_table *crte, #endif err = in_pcbmodify_txrtlmt(tp->t_inpcb, nrte->rate); if (err) { + struct tcp_rate_set *lrs; + uint64_t pre; + rl_decrement_using(nrte); + lrs = __DECONST(struct tcp_rate_set *, rs); + pre = atomic_fetchadd_64(&lrs->rs_flows_using, -1); /* Do we still have a snd-tag attached? */ if (tp->t_inpcb->inp_snd_tag) in_pcbdetach_txrtlmt(tp->t_inpcb); + + if (pre == 1) { + struct epoch_tracker et; + + NET_EPOCH_ENTER(et); + mtx_lock(&rs_mtx); + /* + * Is it dead? + */ + if (lrs->rs_flags & RS_IS_DEAD) + rs_defer_destroy(lrs); + mtx_unlock(&rs_mtx); + NET_EPOCH_EXIT(et); + } if (error) *error = err; return (NULL);