From nobody Mon Dec 19 15:41:32 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 4NbP7x4f73z1G1xT; Mon, 19 Dec 2022 15:41:33 +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 4NbP7x0Dw0z3HBJ; Mon, 19 Dec 2022 15:41:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671464493; 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=9YbVf6pKMIuB0JwpW3+qUV9cQuPsuO1Xs1ZYGcbhqkI=; b=t51DKSBEy1mgL3fSlZxUkb0NzcEjyyQ+Ss+dQerTW+uevHwM8ua3U3B5B4V06dY8I690+Q l4jqhyURkovSLXvJTDMxpxHIMuoKscFCqQAtMiSvtAMIkgYHkE/6VRJkzove1TzCWO15ea DSjiFWadpEADbh9jUnAtTlDf8F6cb+rvnHp7jqyLKTpOqi90XSE7jKy6gtbZXo/jKGPOkn uT6ggyUgri4MfbkFRJvMOk4XBf10rONJrI6HEBXDsnBLK9gO5gB0jx9Q1+tyhgBQHkRSZS 0HZHKz1GpTzIKrqGAwEGuUj2oWgJJr8vrXjCg/+mJrCZ7uh9At0gi/M1hK9acw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671464493; 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=9YbVf6pKMIuB0JwpW3+qUV9cQuPsuO1Xs1ZYGcbhqkI=; b=jFOkVwSow7LIqjT3d2CTpy4xObPp8xaiK3bA7rnqBuyTr9G8RirjUnMPutF5DoXcUGw5n8 76Gc5pGMiSn/a58+I2xfFCA5BuB57J7nexT6ApM2sNOZXFSdBLgGulEvWoMKkOioVhyP1G o8ImOeuZcF6eWDyVxoV1dgQrvC8kG+Cf4xuJtrYn5jPCzcCPLbXoWNiUd83zB9BhuiVrB3 YEN/ezs0AK45XQKQ22FNcB9XmG6Ig7npMtiRuSS+AYq0a1A/BuCCq+CxMyJpArkb7lQ6/T i68HFKuifauox1AUqCb6W9e54nLK5TjhiG5b9Ctl+N10p65haSLEJFmnigx8jQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1671464493; a=rsa-sha256; cv=none; b=fAboH1OF36GERFZq0LSSjyzRXDoVfr5sO/e0Otf+1Mm1oFt7Qcapfe3GzJPZW8gjVsxrwj /lRmzrwrNAXTHttDCXcwOO5QZStPKwuPTYPcmf5S7eMizL+ldzzI0K/zfPcwiFbCjOIskY qjkxjTGKnTQ57u5sgQ2Gf3yBkJ6oQ8B4RnYE6ZzpdtkNoh5CMcD2tktmMyUeG19u4OmRQf knhcPLZpb7fHcCDlQy0kod4FEme6NPyDOPSU7yAv89hhoNRyHjUP8suNfhszFVYsOC7EgW 6nnkKJpfmp8DlswBSwUjHJJlrs6Gp3lkpUFOoe+6BkllshW/DNrEq7xP1bb1ew== 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 4NbP7w6SSQz11DK; Mon, 19 Dec 2022 15:41:32 +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 2BJFfWMS096814; Mon, 19 Dec 2022 15:41:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BJFfW6t096813; Mon, 19 Dec 2022 15:41:32 GMT (envelope-from git) Date: Mon, 19 Dec 2022 15:41:32 GMT Message-Id: <202212191541.2BJFfW6t096813@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: ebf66b2a3b39 - stable/13 - bridge: Fix a potential memory leak in bridge_enqueue() 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: ebf66b2a3b393bd060012c4684bbd525a5da745c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=ebf66b2a3b393bd060012c4684bbd525a5da745c commit ebf66b2a3b393bd060012c4684bbd525a5da745c Author: Mark Johnston AuthorDate: 2022-12-11 16:40:12 +0000 Commit: Mark Johnston CommitDate: 2022-12-19 14:56:46 +0000 bridge: Fix a potential memory leak in bridge_enqueue() A comment at the beginning of the function notes that we may be transmitting multiple fragments as distinct packets. So, the function loops over all fragments, transmitting each mbuf chain. If if_transmit fails, we need to free all of the fragments, but m_freem() only frees an mbuf chain - it doesn't follow m_nextpkt. Change the error handler to free each untransmitted packet fragment, and count each fragment as a separate error since we increment OPACKETS once per fragment when transmission is successful. Reviewed by: zlei, kp MFC after: 1 week Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D37635 (cherry picked from commit 51088797305c8aba43e8ded60b99eef5baa14071) --- sys/net/if_bridge.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c index e644f1db55c2..0473245a1abd 100644 --- a/sys/net/if_bridge.c +++ b/sys/net/if_bridge.c @@ -2028,8 +2028,13 @@ bridge_enqueue(struct bridge_softc *sc, struct ifnet *dst_ifp, struct mbuf *m) M_ASSERTPKTHDR(m); /* We shouldn't transmit mbuf without pkthdr */ if ((err = dst_ifp->if_transmit(dst_ifp, m))) { - m_freem(m0); - if_inc_counter(sc->sc_ifp, IFCOUNTER_OERRORS, 1); + int n; + + for (m = m0, n = 1; m != NULL; m = m0, n++) { + m0 = m->m_nextpkt; + m_freem(m); + } + if_inc_counter(sc->sc_ifp, IFCOUNTER_OERRORS, n); break; }