From nobody Thu Feb 10 20:39:42 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 2E27019CC7FD; Thu, 10 Feb 2022 20:39:43 +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 4JvpWz0SBjz3tym; Thu, 10 Feb 2022 20:39:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644525583; 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=IQvLwAqQls2XuW2ALMbtLamd1Gj5mlXJW5ZQOPZktMo=; b=xCgFnnDjiIw1h2TI8qY3hLvL25HFu3KV9l8+H76GzxJ/519GoD9TtZqgVj2zD7FKt7ZGlP 6C2N+MPkPrpMuP4p0UpIQrXkiFKx5WdegK36o5O3OpeyowpNZI/GkNq/n6CSRPqiYyx7ZK RszAsPUBc2FP+wVXb7kJe00WI8XLwPLj0bverQJC4nClidAGFs4WY77nuvceR1NGHZlZ/M TD2b52F+2605nC1EOO3VcDJ3ONXbn3bnQjCJKY8UpUOn49EB/szxjHzZagp/mDlVdypGb8 WR2rPpu23oAPzlBYkmqG9FNnqf+LoE6FXmbyCz0WcPs+WXCQIH79Oph3tAoNsg== 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 D29FD271A6; Thu, 10 Feb 2022 20:39:42 +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 21AKdgCG003131; Thu, 10 Feb 2022 20:39:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21AKdgsj003130; Thu, 10 Feb 2022 20:39:42 GMT (envelope-from git) Date: Thu, 10 Feb 2022 20:39:42 GMT Message-Id: <202202102039.21AKdgsj003130@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Andrew Gallatin Subject: git: bf2a85f4e304 - stable/13 - Fix a memory leak when ip_output_send() returns EAGAIN due to send tag issues 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/stable/13 X-Git-Reftype: branch X-Git-Commit: bf2a85f4e304aa6223ab007231e71b707320600e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644525583; 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=IQvLwAqQls2XuW2ALMbtLamd1Gj5mlXJW5ZQOPZktMo=; b=jmhcZbS/fXM9+0l0tvFK9bVogy8oWdq8cKXvFa+GRHpCwEWvV95s8itjUp7dlF44l52qYC CWJW0corXR8DldqhZiXzsB6Hj8MK6sSt4eOSdbbGtk3CUsJNF05/TV+5urWjyxYC4hWDAh BOJ2wr3lJS01GfWPSIMx6bvQ6wN7rYJXSd3YoPBKDoiwlS4A8qfDmMq0qR7NTbBgd2N1X3 YwxDtkBMm0kLnFOJnjUPXq9emn9F1BGDJK6NE7+Vxlyyvv5ncMe99qvhwn5wsjFRuT8gmI r469KE0FNeK18XlavC+Z3HKzmRaXZot08/q14zza2PPcViMYN9COWHa40nDCLA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644525583; a=rsa-sha256; cv=none; b=FoFrRI4ohX0T1AVe+bgnJ5UZxBsvdH/gii2v7QA/nQTZ5htsn2uXblqCpfTAaquB0jeM7v rQzhv4rXyv7iR8WfnbmORDrGyjno7/qvFnSLqyFsT54UyG+g9HPPNJGAWcRn1CNg5ekwLG MOB+aySBcbVrO7SFCNk/RjryBO/TiCqvhCBBP86suYVMhM0ZGZX1NfHPEy2J2CNGUKknV4 b7Fv6QcE1SvXOTFobCCvIWMqYHS2vDqkFoV3S4OLH5Gs8ul/D0FbTp4BvvvjnT7on+mAQt M/3hstW/Q21zB3tsADLRX7ZRTLlAhsLO4kdNsA/Av5mP7jPBKnIAdjTV5wF8ww== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by gallatin: URL: https://cgit.FreeBSD.org/src/commit/?id=bf2a85f4e304aa6223ab007231e71b707320600e commit bf2a85f4e304aa6223ab007231e71b707320600e Author: Andrew Gallatin AuthorDate: 2022-01-27 15:28:15 +0000 Commit: Andrew Gallatin CommitDate: 2022-02-10 20:39:22 +0000 Fix a memory leak when ip_output_send() returns EAGAIN due to send tag issues When ip_output_send() returns EAGAIN due to issues with send tags (route change, lagg failover, etc), it must free the mbuf. This is because ip_output_send() was written as a wrapper/replacement for a direct call to if_output(), and the contract with if_output() has historically been that it owns the mbufs once called. When ip_output_send() failed to free mbufs, it violated this assumption and lead to leaked mbufs. This was noticed when using NIC TLS in combination with hardware rate-limited connections. When seeing lots of NIC output drops triggered ratelimit send tag changes, we noticed we were leaking ktls_sessions, send tags and mbufs. This was due ip_output_send() leaking mbufs which held references to ktls_sessions, which in turn held references to send tags. Many thanks to jbh, rrs, hselasky and markj for their help in debugging this. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D34054 Reviewed by: hselasky, jhb, rrs MFC after: 2 weeks (cherry picked from commit 9ba117960e1755a693f9361e4d076630dfe13dba) --- sys/netinet/ip_output.c | 2 ++ sys/netinet6/ip6_output.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index a011c28441bd..a23a38b08fa8 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -239,6 +239,7 @@ ip_output_send(struct inpcb *inp, struct ifnet *ifp, struct mbuf *m, * packet. */ if (mst == NULL) { + m_freem(m); error = EAGAIN; goto done; } @@ -263,6 +264,7 @@ ip_output_send(struct inpcb *inp, struct ifnet *ifp, struct mbuf *m, KASSERT(m->m_pkthdr.rcvif == NULL, ("trying to add a send tag to a forwarded packet")); if (mst->ifp != ifp) { + m_freem(m); error = EAGAIN; goto done; } diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c index 209169dbdabd..de9ed673de79 100644 --- a/sys/netinet6/ip6_output.c +++ b/sys/netinet6/ip6_output.c @@ -336,6 +336,7 @@ ip6_output_send(struct inpcb *inp, struct ifnet *ifp, struct ifnet *origifp, * packet. */ if (mst == NULL) { + m_freem(m); error = EAGAIN; goto done; } @@ -360,6 +361,7 @@ ip6_output_send(struct inpcb *inp, struct ifnet *ifp, struct ifnet *origifp, KASSERT(m->m_pkthdr.rcvif == NULL, ("trying to add a send tag to a forwarded packet")); if (mst->ifp != ifp) { + m_freem(m); error = EAGAIN; goto done; }