git: 798531d5964b - stable/15 - pflow: Destroy exporters on module unload

From: R. Christian McDonald <rcm_at_FreeBSD.org>
Date: Wed, 28 Oct 2026 20:36:01 UTC
The branch stable/15 has been updated by rcm:

URL: https://cgit.FreeBSD.org/src/commit/?id=798531d5964b8aec80fdd6697b61bed89f7a5b11

commit 798531d5964b8aec80fdd6697b61bed89f7a5b11
Author:     R. Christian McDonald <rcm@FreeBSD.org>
AuthorDate: 2026-10-19 20:18:25 +0000
Commit:     R. Christian McDonald <rcm@FreeBSD.org>
CommitDate: 2026-10-28 20:34:17 +0000

    pflow: Destroy exporters on module unload
    
    Since 83641335f96c only jail removal destroys exporters.  Unloading
    pflow with one left trips the assertion in vnet_pflowdetach() or,
    without INVARIANTS, leaves pf calling into the freed module the next
    time it removes a state that pflow exports.
    
    Reviewed by:    kp
    Fixes:          83641335f96c ("pf: clean up pflow sockets on jail removal")
    MFC after:      1 week
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    
    (cherry picked from commit c91539772b07cb78369626716a4ddf92cf6caa5f)
---
 sys/netpfil/pf/pflow.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sys/netpfil/pf/pflow.c b/sys/netpfil/pf/pflow.c
index d30b80c88d89..7b9fa5bc7249 100644
--- a/sys/netpfil/pf/pflow.c
+++ b/sys/netpfil/pf/pflow.c
@@ -205,8 +205,12 @@ pflow_jail_remove(void *obj, void *data __unused)
 static void
 vnet_pflowdetach(void)
 {
+	struct pflow_softc	*sc, *tmp;
+
+	/* Left on module unload; drain before the counters are freed. */
+	CK_LIST_FOREACH_SAFE(sc, &V_pflowif_list, sc_next, tmp)
+		pflow_destroy(sc->sc_id, true);
 
-	/* Should have been done by pflow_jail_remove() */
 	MPASS(CK_LIST_EMPTY(&V_pflowif_list));
 	delete_unrhdr(V_pflow_unr);
 	mtx_destroy(&V_pflowif_list_mtx);