From nobody Thu Jan 27 15:34:50 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 6E8F419749D6; Thu, 27 Jan 2022 15:34:50 +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 4Jl4Qf2Wtdz4pB2; Thu, 27 Jan 2022 15:34:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643297690; 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=qmADxkAnC/aCV5RiBO1CAq+NWXaV9b8WSzLVyCgU/pk=; b=L+TdvIQ5F0SB2voxjwQigurZ9C6M06OVQIJ1vrI/S8HjkY4sJUb7jbSPvMaQs3i6KZmsAI NZoRnk3LTu8I6KVSJn/bU4uoxKH1zcl2u+I7gI7GYlmrs0IwVGWAJmT+o4uvj4TRaFi7Qf QYzTzH78JGut7D4j6j/8s0wD6OrmjB8qgSHYfBGJdDSOSuwd4THFMoRZApbGJAo9nOIAHU cxDeMqk1tjBf59Tb/lCYOkVFCNgYx6fUrq2Bhi+Z2phVgQSC1W1T6g/W2PpFM5GcE3R66q NAy89cOSQBWsdkbm/RsNC8txvAg+n6L/FZdge60pnWshw62BcLMdemBMhDOWlw== 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 2C5FB193AE; Thu, 27 Jan 2022 15:34:50 +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 20RFYo37033045; Thu, 27 Jan 2022 15:34:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20RFYoZA033044; Thu, 27 Jan 2022 15:34:50 GMT (envelope-from git) Date: Thu, 27 Jan 2022 15:34:50 GMT Message-Id: <202201271534.20RFYoZA033044@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: 9ba117960e17 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 9ba117960e1755a693f9361e4d076630dfe13dba Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643297690; 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=qmADxkAnC/aCV5RiBO1CAq+NWXaV9b8WSzLVyCgU/pk=; b=Giy2KhodBrTRf/9v4BVeaHYYyJcoHW5Z7/p1hweULc0qxWydARdVbHlxbDBlPFTywSHoJJ KZZzSRFhfHpR00XThxCMW/4q26gcg9gLv5BXE1ch+NzL1DaZynrldgGpAT9qkA/zejdCrc rn8Qil5KL+r2/InuckXqbcyCQxko6Mohiof2JnIhDLSls4zOkCqm/X6LcO7TTZqIOtzwWq 7IQDbR7cnSrVR2OIkF3a7VYPWDadvTMWE1m0aZ/cXiae6g8Q+Lo64PmXeqIzl6sdubW+iR M36P2SwFgBhXY20mC7ERolryshEEHXpOpHv/nzjSgAmqggrqG2ITSko+LK5NAg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643297690; a=rsa-sha256; cv=none; b=W91sIe5C5qS1DQANkWb+fe6U3K+DEkkwoJ8jmkcZUS9G5j8zxkZSlZJkCcUdADBXSnfhEI FYLIo6yNP2dHCisCPVRYry7h1Rh96YvesVUJgibVjAofIooj8+j0vJQQBmPXdJZ5rynjGj lOPqj5zCuCB6Ivyx4FXLCXdAYjchXyIIEmQMEID/y7pVMiHhmj69mLXUqkgXBUDS9kriBV 3ObOUFeGoRfx1KuuR91syNLf7hjnqnzXq6P09UbU3Noi4DWTCl3Nh0EQG4l/ufYTCIiF6J 4U/gADDbtFcWXZAbp+9hHoR/v/NH4aMpr6P/EBfGH5kb/UJxjRc1p0rv0h/tqQ== 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=9ba117960e1755a693f9361e4d076630dfe13dba commit 9ba117960e1755a693f9361e4d076630dfe13dba Author: Andrew Gallatin AuthorDate: 2022-01-27 15:28:15 +0000 Commit: Andrew Gallatin CommitDate: 2022-01-27 15:34:34 +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 --- 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 e30339f8c4aa..f203bc165e61 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 848ec6694398..406776bdb5a4 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; }