From nobody Wed Dec 28 09:07:21 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 4Nhlyy0gYrz2cHsb; Wed, 28 Dec 2022 09:07:22 +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 4Nhlyx6f6Kz47P5; Wed, 28 Dec 2022 09:07:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1672218441; 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=DQ/R7SxGmzUi/9PZ29njiUDb896/MTY4KvNiNvkuRX0=; b=E2bwB+1TDk9pIwakGJGVSep9OfjZj0Q97upVnW7wGKAz6Qw0dYCALeYjtBz+T5fBau1d4m frsQcEvFBwGvMvLz/UtmPdFJo+pOn5lc9TXwd1dO8poOjOxFk9hJyGC+l5WI4waaVbwQ/x 8xMXf5IMAaqHGNpl48M3F6Cv/0/RgB6Y1p5o93ddnxNVk1sowkMIcnj4mqvKvg7rNXAuOv Y626mG7GYCdf7spq29E8RFFh7L9ZiOBGNkXGy0XrZx2Vb+kkLNpt1cj0GaJAXkhoKyC7Zq abOF8njPMKBHzpuaQKvat63ilcIV2K2A8IFpVZm8ngfJrdjhsgfupVAeLH1q3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1672218441; 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=DQ/R7SxGmzUi/9PZ29njiUDb896/MTY4KvNiNvkuRX0=; b=r+DAzifdxCLPkTGZ4XP89wMaAOsclqiDcY7JKrBkcESv1ZZMsKdYSAXdkrEoKpMHgQuuTf UYy4KyE0OVILRgwxMEebDScdB6Tinm1nOWQeCSG92Lhun6q68aRPjwQxhI0Xqk2jsC37/b HXwrloJpljazQjtHAmsS86KTUzB44OC6S2BYfMn3XXc5+Ug5WTJS1T5JyczSvhiiqV8LsA iKCPFSVSfXDRxIA/yTnjO2CQPb5mHLlopXnYK4d3/xpwPYvcXYUeNAUk3n3PaTbHT7y8Wj b7UnzJFSSoVoOqbz8lN50xXPVeBnWq2mLmqqxTctnshEIuKBaGwD5RbAVwaLMw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1672218441; a=rsa-sha256; cv=none; b=VEtf1wbvvC3nk7INcTjw6MaQ/UldA+x7xfn2A8cL9S3Og5L7/UiUfx+y9xKpybhh3E4XiX IE/7xUFbvW7JfNX/EBRMLcMixaXlcdKOzxbxLt2YP46H6RINdiPrYnuEsB3DLApYjH+Dnw PlUnvz3Msj6/eMOEop5wWirjL8kfCsgQqDCBviIijdNs4hTGZC4pKxF3R0TB3BPTDfhEsr EKsGu/hfxBZoKNCNd/E5lOGcXh2EgKLwPClG0PwgHsABEBFLj77MzyNxsx8GP7rbONWpha t/JVUbHZG3L23GpB8koowSF7xcq8Af3ER4jNK2XwHp0l1gt+8QPN3M36Q7MUPA== 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 4Nhlyx5M2HzkWw; Wed, 28 Dec 2022 09:07:21 +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 2BS97L7R059199; Wed, 28 Dec 2022 09:07:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BS97LmI059198; Wed, 28 Dec 2022 09:07:21 GMT (envelope-from git) Date: Wed, 28 Dec 2022 09:07:21 GMT Message-Id: <202212280907.2BS97LmI059198@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: 909167374fef - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: 909167374fefcfa4981e4a43ee48872dcf76d0e2 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=909167374fefcfa4981e4a43ee48872dcf76d0e2 commit 909167374fefcfa4981e4a43ee48872dcf76d0e2 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 aebda6d9e3ea..38e1ebbb61b7 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1622,14 +1622,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(); }