Index: sys/net/bpf.c =================================================================== --- sys/net/bpf.c (revision 236540) +++ sys/net/bpf.c (working copy) @@ -2542,13 +2542,23 @@ bpf_ifdetach(void *arg __unused, struct ifnet *ifp { struct bpf_if *bp; - if ((bp = ifp->if_bpf) == NULL) + BPF_LOCK(); + if ((bp = ifp->if_bpf) == NULL) { + BPF_UNLOCK(); return; + } + if ((bp->flags & BPFIF_FLAG_DYING) == 0) { + BPF_UNLOCK(); + return; + } + CTR3(KTR_NET, "%s: freing BPF instance %p for interface %p", __func__, bp, ifp); ifp->if_bpf = NULL; + BPF_UNLOCK(); + rw_destroy(&bp->bif_lock); free(bp, M_BPF); }