Mon Jan 25 17:17:19 2021 UTC ()
Fix locking issue: npf_default_pass needs to be called with the config lock
held.


(christos)
diff -r1.19 -r1.20 src/sys/net/npf/npf_os.c

cvs diff -r1.19 -r1.20 src/sys/net/npf/npf_os.c (expand / switch to unified diff)

--- src/sys/net/npf/npf_os.c 2020/08/18 07:53:24 1.19
+++ src/sys/net/npf/npf_os.c 2021/01/25 17:17:19 1.20
@@ -23,27 +23,27 @@ @@ -23,27 +23,27 @@
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE. 27 * POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30/* 30/*
31 * NPF main: dynamic load/initialisation and unload routines. 31 * NPF main: dynamic load/initialisation and unload routines.
32 */ 32 */
33 33
34#ifdef _KERNEL 34#ifdef _KERNEL
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36__KERNEL_RCSID(0, "$NetBSD: npf_os.c,v 1.19 2020/08/18 07:53:24 maxv Exp $"); 36__KERNEL_RCSID(0, "$NetBSD: npf_os.c,v 1.20 2021/01/25 17:17:19 christos Exp $");
37 37
38#ifdef _KERNEL_OPT 38#ifdef _KERNEL_OPT
39#include "pf.h" 39#include "pf.h"
40#if NPF > 0 40#if NPF > 0
41#error "NPF and PF are mutually exclusive; please select one" 41#error "NPF and PF are mutually exclusive; please select one"
42#endif 42#endif
43#endif 43#endif
44 44
45#include <sys/param.h> 45#include <sys/param.h>
46#include <sys/types.h> 46#include <sys/types.h>
47 47
48#include <sys/conf.h> 48#include <sys/conf.h>
49#include <sys/kauth.h> 49#include <sys/kauth.h>
@@ -311,28 +311,36 @@ npf_dev_poll(dev_t dev, int events, lwp_ @@ -311,28 +311,36 @@ npf_dev_poll(dev_t dev, int events, lwp_
311{ 311{
312 return ENOTSUP; 312 return ENOTSUP;
313} 313}
314 314
315static int 315static int
316npf_dev_read(dev_t dev, struct uio *uio, int flag) 316npf_dev_read(dev_t dev, struct uio *uio, int flag)
317{ 317{
318 return ENOTSUP; 318 return ENOTSUP;
319} 319}
320 320
321bool 321bool
322npf_autounload_p(void) 322npf_autounload_p(void)
323{ 323{
 324 if (npf_active_p())
 325 return false;
 326
324 npf_t *npf = npf_getkernctx(); 327 npf_t *npf = npf_getkernctx();
325 return !npf_active_p() && npf_default_pass(npf); 328
 329 npf_config_enter(npf);
 330 bool pass = npf_default_pass(npf);
 331 npf_config_exit(npf);
 332
 333 return pass;
326} 334}
327 335
328/* 336/*
329 * Interface operations. 337 * Interface operations.
330 */ 338 */
331 339
332static const char * 340static const char *
333npf_ifop_getname(npf_t *npf __unused, ifnet_t *ifp) 341npf_ifop_getname(npf_t *npf __unused, ifnet_t *ifp)
334{ 342{
335 return ifp->if_xname; 343 return ifp->if_xname;
336} 344}
337 345
338static ifnet_t * 346static ifnet_t *