Author: kp
Date: Wed May  3 20:56:54 2017
New Revision: 317773
URL: https://svnweb.freebsd.org/changeset/base/317773

Log:
  pf: Fix panic on unload
  
  vnet_pf_uninit() is called through vnet_deregister_sysuninit() and
  linker_file_unload() when the pf module is unloaded. This is executed
  after pf_unload() so we end up trying to take locks which have been
  destroyed already.
  
  Move pf_unload() to a separate SYSUNINIT() to ensure it's called after
  all the vnet_pf_uninit() calls.
  
  Differential Revision:        https://reviews.freebsd.org/D10025

Modified:
  head/sys/netpfil/pf/pf_ioctl.c

Modified: head/sys/netpfil/pf/pf_ioctl.c
==============================================================================
--- head/sys/netpfil/pf/pf_ioctl.c      Wed May  3 20:56:34 2017        
(r317772)
+++ head/sys/netpfil/pf/pf_ioctl.c      Wed May  3 20:56:54 2017        
(r317773)
@@ -178,7 +178,7 @@ static int          hook_pf(void);
 static int             dehook_pf(void);
 static int             shutdown_pf(void);
 static int             pf_load(void);
-static int             pf_unload(void);
+static void            pf_unload(void);
 
 static struct cdevsw pf_cdevsw = {
        .d_ioctl =      pfioctl,
@@ -3789,10 +3789,9 @@ pf_unload_vnet(void)
                pf_mtag_cleanup();
 }
 
-static int
+static void
 pf_unload(void)
 {
-       int error = 0;
 
        sx_xlock(&pf_end_lock);
        pf_end_threads = 1;
@@ -3810,8 +3809,6 @@ pf_unload(void)
        rw_destroy(&pf_rules_lock);
        sx_destroy(&pf_ioctl_lock);
        sx_destroy(&pf_end_lock);
-
-       return (error);
 }
 
 static void
@@ -3829,6 +3826,7 @@ vnet_pf_uninit(const void *unused __unus
 
        pf_unload_vnet();
 } 
+SYSUNINIT(pf_unload, SI_SUB_PROTO_FIREWALL, SI_ORDER_SECOND, pf_unload, NULL);
 VNET_SYSUNINIT(vnet_pf_uninit, SI_SUB_PROTO_FIREWALL, SI_ORDER_THIRD,
     vnet_pf_uninit, NULL);
 
@@ -3849,7 +3847,8 @@ pf_modevent(module_t mod, int type, void
                error = EBUSY;
                break;
        case MOD_UNLOAD:
-               error = pf_unload();
+               /* Handled in SYSUNINIT(pf_unload) to ensure it's done after
+                * the vnet_pf_uninit()s */
                break;
        default:
                error = EINVAL;
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to