From nobody Wed Dec 14 09:20:07 2022 X-Original-To: dev-commits-src-main@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 4NX8w744FJz4k87M; Wed, 14 Dec 2022 09:20:07 +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 4NX8w73Yrwz3x4d; Wed, 14 Dec 2022 09:20:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671009607; 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=600jQRBVD1ZSzeW1PdCY3jWXb+A5mmWJT0HbFy+9ZDw=; b=jDf3uJAtfIyfv6KxJRuAc5fUwpZJHA0IaOoU85uf/EKDjwqcSGQCqFKiDImz9iGP1oHsyW 5yXz/kGzaMIX/HbmgcHUs+aMjf25k3IIKdvUdofFK0l9QI93Wk26h3BGur8yKpMxsjqb+L ptvGo/aJ24kfNv8jopPbY5z976f+e7J/7QnUNkolkxxKg95TBfZCpWbmJwFWieB1iKpW6/ L6iJfCXpoPwJieML2kF26Q2h5UYerMEEAstsQyE+pEbep4snVAVRYKIqb88UZHiVELVCRr jW75+C0X/PD3x9sRxbC6bP3u7fDQGmMXABwUgc3sdd1ufPTzXsoVirauY2ahsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671009607; 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=600jQRBVD1ZSzeW1PdCY3jWXb+A5mmWJT0HbFy+9ZDw=; b=W8DbW0xlYdaNDJTm4IcBoAi4+hme3idftCkHHwXdF3nA8QUuHhq3do8yBdjEhhuB7oCpbB jDLH/8kd99ye64b21rk+YAlQqDTPIxcoLsNj67L9Rwhopq+9ALN4i0Uzwyu1n2g8A+9jG0 IxG5lgPEv+GF+NnTmR32wU5TAR8FSMtVcxLiAubl9zZe35wvNZ2wZrPly5PPQzddOhD4tU tnhBN9JtcitUs40LnEPvFqvsfaxxThcZfxW1WTw48On2j9TtFyBfrruCyb34fCTO7da4Dd 8itIBK72s5zKv5jiuuPIhJ6qF3SB/URb3JOeffSHfTDdzoCh6OrW0xXsf4n/dQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1671009607; a=rsa-sha256; cv=none; b=Mr173rzIEsscfn7ZWZqTFppkTUSeOqU4sm413vzNJg2X/dUIVJ3yJ0RbIBnGxgEZ8SUMwK XzjoGsH+zSy3NGrnWojBc+Oopk6oFPbjMRbZ19HVoJUcCzqbeBSgTP0jos8jg4GZp1363m F2zLyqXqYM805d9yziQlLi+fw2ILP46zx5Fc1VVREjwu1s1ReQUNRNiEh9LffyqguqKaqc oVIC+NAe+WV9M4HZeskyWEHePH7H+SsNuD/iVFOimTuP0Y8MvZ7rZts/FI1nlWMDFyjKn9 eUAAOrPYhzXAAGeNR+7+0D1V0o6htxs8mcNodE8WQsB/nBKP+z0UE6GFc4L46A== 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 4NX8w72cqQzpPP; Wed, 14 Dec 2022 09:20:07 +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 2BE9K7GH036126; Wed, 14 Dec 2022 09:20:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BE9K7bQ036123; Wed, 14 Dec 2022 09:20:07 GMT (envelope-from git) Date: Wed, 14 Dec 2022 09:20:07 GMT Message-Id: <202212140920.2BE9K7bQ036123@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: bfeef0d32a00 - main - pf: fix pfi_ifnet leak on interface removal List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: bfeef0d32a0036bf6bec93a439e0466efe6f4482 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=bfeef0d32a0036bf6bec93a439e0466efe6f4482 commit bfeef0d32a0036bf6bec93a439e0466efe6f4482 Author: Nick Reilly AuthorDate: 2022-11-30 14:19:44 +0000 Commit: Kristof Provost CommitDate: 2022-12-14 09:19:01 +0000 pf: fix pfi_ifnet leak on interface removal The detach of the interface and group were leaving pfi_ifnet memory behind. Check if the kif still has references, and clean it up if it doesn't On interface detach, the group deletion was notified first and then a change notification was sent. This would recreate the group in the kif layer. Reorder the change to before the delete. PR: 257218 MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D37569 --- sys/net/if.c | 3 +-- sys/netpfil/pf/pf_if.c | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index 7cbb750d3ab1..970d1398f870 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1545,14 +1545,13 @@ _if_delgroup_locked(struct ifnet *ifp, struct ifg_list *ifgl, IFNET_WUNLOCK(); epoch_wait_preempt(net_epoch_preempt); + EVENTHANDLER_INVOKE(group_change_event, groupname); if (freeifgl) { EVENTHANDLER_INVOKE(group_detach_event, ifgl->ifgl_group); free(ifgl->ifgl_group, M_TEMP); } free(ifgm, M_TEMP); free(ifgl, M_TEMP); - - EVENTHANDLER_INVOKE(group_change_event, groupname); } /* diff --git a/sys/netpfil/pf/pf_if.c b/sys/netpfil/pf/pf_if.c index f572d80c219f..71bd215d3d24 100644 --- a/sys/netpfil/pf/pf_if.c +++ b/sys/netpfil/pf/pf_if.c @@ -364,14 +364,11 @@ pfi_kkif_ref(struct pfi_kkif *kif) kif->pfik_rulerefs++; } -void -pfi_kkif_unref(struct pfi_kkif *kif) +static void +pfi_kkif_remove_if_unref(struct pfi_kkif *kif) { PF_RULES_WASSERT(); - KASSERT(kif->pfik_rulerefs > 0, ("%s: %p has zero refs", __func__, kif)); - - kif->pfik_rulerefs--; if (kif->pfik_rulerefs > 0) return; @@ -391,6 +388,18 @@ pfi_kkif_unref(struct pfi_kkif *kif) mtx_unlock(&pfi_unlnkdkifs_mtx); } +void +pfi_kkif_unref(struct pfi_kkif *kif) +{ + + PF_RULES_WASSERT(); + KASSERT(kif->pfik_rulerefs > 0, ("%s: %p has zero refs", __func__, kif)); + + kif->pfik_rulerefs--; + + pfi_kkif_remove_if_unref(kif); +} + void pfi_kkif_purge(void) { @@ -1039,6 +1048,8 @@ pfi_detach_ifnet_event(void *arg __unused, struct ifnet *ifp) #ifdef ALTQ pf_altq_ifnet_event(ifp, 1); #endif + pfi_kkif_remove_if_unref(kif); + PF_RULES_WUNLOCK(); NET_EPOCH_EXIT(et); } @@ -1099,6 +1110,8 @@ pfi_detach_group_event(void *arg __unused, struct ifg_group *ifg) kif->pfik_group = NULL; ifg->ifg_pf_kif = NULL; + + pfi_kkif_remove_if_unref(kif); PF_RULES_WUNLOCK(); }