The branch main has been updated by zlei:

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

commit edc307eca9a9a9b0ce7445cff513b48f6489e5c6
Author:     Zhenlei Huang <z...@freebsd.org>
AuthorDate: 2025-06-28 15:46:51 +0000
Commit:     Zhenlei Huang <z...@freebsd.org>
CommitDate: 2025-06-28 15:46:51 +0000

    pfsync: Allocate and initialize buckets before attaching the interface
    
    This prevents a potential race that the ioctl threads see NULL or
    uninitialized buckets.
    
    Reviewed by:    kp
    Fixes:          4fc65bcbe3fb pfsync: Performance improvement
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D51064
---
 sys/netpfil/pf/if_pfsync.c | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/sys/netpfil/pf/if_pfsync.c b/sys/netpfil/pf/if_pfsync.c
index d5d77fa1ae1d..fdedb9424117 100644
--- a/sys/netpfil/pf/if_pfsync.c
+++ b/sys/netpfil/pf/if_pfsync.c
@@ -397,23 +397,6 @@ pfsync_clone_create(struct if_clone *ifc, int unit, 
caddr_t param)
        sc->sc_flags |= PFSYNCF_OK;
        sc->sc_maxupdates = 128;
        sc->sc_version = PFSYNC_MSG_VERSION_DEFAULT;
-
-       ifp = sc->sc_ifp = if_alloc(IFT_PFSYNC);
-       if_initname(ifp, pfsyncname, unit);
-       ifp->if_softc = sc;
-       ifp->if_ioctl = pfsyncioctl;
-       ifp->if_output = pfsyncoutput;
-       ifp->if_hdrlen = sizeof(struct pfsync_header);
-       ifp->if_mtu = ETHERMTU;
-       mtx_init(&sc->sc_mtx, pfsyncname, NULL, MTX_DEF);
-       mtx_init(&sc->sc_bulk_mtx, "pfsync bulk", NULL, MTX_DEF);
-       callout_init_mtx(&sc->sc_bulk_tmo, &sc->sc_bulk_mtx, 0);
-       callout_init_mtx(&sc->sc_bulkfail_tmo, &sc->sc_bulk_mtx, 0);
-
-       if_attach(ifp);
-
-       bpfattach(ifp, DLT_PFSYNC, PFSYNC_HDRLEN);
-
        sc->sc_buckets = mallocarray(pfsync_buckets, sizeof(*sc->sc_buckets),
            M_PFSYNC, M_ZERO | M_WAITOK);
        for (c = 0; c < pfsync_buckets; c++) {
@@ -435,6 +418,22 @@ pfsync_clone_create(struct if_clone *ifc, int unit, 
caddr_t param)
                b->b_snd.ifq_maxlen = ifqmaxlen;
        }
 
+       ifp = sc->sc_ifp = if_alloc(IFT_PFSYNC);
+       if_initname(ifp, pfsyncname, unit);
+       ifp->if_softc = sc;
+       ifp->if_ioctl = pfsyncioctl;
+       ifp->if_output = pfsyncoutput;
+       ifp->if_hdrlen = sizeof(struct pfsync_header);
+       ifp->if_mtu = ETHERMTU;
+       mtx_init(&sc->sc_mtx, pfsyncname, NULL, MTX_DEF);
+       mtx_init(&sc->sc_bulk_mtx, "pfsync bulk", NULL, MTX_DEF);
+       callout_init_mtx(&sc->sc_bulk_tmo, &sc->sc_bulk_mtx, 0);
+       callout_init_mtx(&sc->sc_bulkfail_tmo, &sc->sc_bulk_mtx, 0);
+
+       if_attach(ifp);
+
+       bpfattach(ifp, DLT_PFSYNC, PFSYNC_HDRLEN);
+
        V_pfsyncif = sc;
 
        return (0);

Reply via email to