From nobody Wed Dec 28 09:03:13 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 4NhltB2XFQz2cHk8; Wed, 28 Dec 2022 09:03:14 +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 4NhltB0y0Pz46cV; Wed, 28 Dec 2022 09:03:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1672218194; 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=YdPH+LZHirl2cNvEF7MVudiX2tSkEA0Ii34JLwN9Vyc=; b=m1841ep8EcvlaEDivcVbzKuEHD6AJbpQ17dNCpyj0/JGy52bSWZVY5yE4GoGFvknXvfSdx cR4xU/swO7zl5Kn5FMrJamC6omissNkVxmcaXsseUSfOlMOmEcpT8edsGJOSKPXuM3O7V2 Mm016JJkdhBiOXoeBIlK0nMPx19GeAZNpAmr5z04kSssS2bX8he1F6lUkP3nljtLu8b5XY U6PoHh2JGI9FLumffTVjDM8q4SdO0AQWNhKal9akVx5efQRrvlmB34bSRr1xalh3XADjRQ QxxWZ7l2VLzYpUANdCGy6OAhVMzenlG0hN9XACK4ahxGPkGuveoh15X/UlGH6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1672218194; 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=YdPH+LZHirl2cNvEF7MVudiX2tSkEA0Ii34JLwN9Vyc=; b=Ilp6iwCJh1pL05/rsYUJEg5EAYpSEePWmwigFm7PQXeiRJkwwDhSx5sm7CPUSHljGFVEoN Pr246KyDFf8VcNvCDvO36WdKSdbmugpD2LXx1DS+4ZsMQftrjq2vJKse8JGqP4Lmh/mPuo gzkXEHRFpR2o7oPRAwQhyKWx/LHuDhSBaIn4yft7PS8YSAiNGak1mNDx1WJnBbWVy0gdJH 2o+8udbjU/4hFGWrqqy3ug3Oocv5sM4ANoqK/ca3pA9ZBs2JbZbDbxhcKEn/d5X/zcyMhV rXMzTH5dN8z8aJxUGMU4if7z0/yF6i8N7rHT3e/UMgE0Guew8bs/dnIxTHGRSw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1672218194; a=rsa-sha256; cv=none; b=cWxFZbsGDQmTASNCgnV1MYF3ZKEnNY9unrDGnXCp1EgTyhwWTNdN7R6+Hjh9TsKaHzFdzG zaNNajkcC8X758nXVFpOY+o2dGHqRSHHULIhmSAmZkutqSENcmxNvmETxFQBzQSXG3E6CV GGWOOVgKLk4nFatw+quUVIvwvxCX5FmvoJhCw++AMrIwWii3YAhwNJ8YI6qopMg1EFcz6E uKUh0PdbOgC4sqIKOXqCPjt5m5TsauBXAbIgzPfGz+NSWiJJuvCCNvdn5Tj7v3MUHI4Bnd tsvn0Tdjg74sfvazDqiF/BqvbK2hjNjHbxPV6tdU6nnvVLb0d2Lx6ZAPcInW8w== 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 4NhltB00NnzkWs; Wed, 28 Dec 2022 09:03:14 +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 2BS93D7k058516; Wed, 28 Dec 2022 09:03:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BS93Dom058515; Wed, 28 Dec 2022 09:03:13 GMT (envelope-from git) Date: Wed, 28 Dec 2022 09:03:13 GMT Message-Id: <202212280903.2BS93Dom058515@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: 5f7454d8904c - stable/12 - pf: fix pfi_ifnet leak on interface removal 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: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 5f7454d8904ca68697dda569f71af6ef5ec178c7 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=5f7454d8904ca68697dda569f71af6ef5ec178c7 commit 5f7454d8904ca68697dda569f71af6ef5ec178c7 Author: Nick Reilly AuthorDate: 2022-11-30 14:19:44 +0000 Commit: Kristof Provost CommitDate: 2022-12-28 04:56:08 +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 (cherry picked from commit bfeef0d32a0036bf6bec93a439e0466efe6f4482) --- 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 f2c306af7095..14f03286358d 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1574,14 +1574,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 55e5e4ccac83..e9d18d717257 100644 --- a/sys/netpfil/pf/pf_if.c +++ b/sys/netpfil/pf/pf_if.c @@ -340,14 +340,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; @@ -367,6 +364,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) { @@ -1012,6 +1021,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(); } @@ -1061,6 +1072,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(); }