NetBSD Problem Report #7802

Received: (qmail 23320 invoked from network); 18 Jun 1999 02:06:00 -0000
Message-Id: <199906180205.WAA00343@rossem.worldmap.net>
Date: Thu, 17 Jun 1999 22:05:58 -0400 (EDT)
From: mike@pelley.com
Reply-To: mike@pelley.com
To: gnats-bugs@gnats.netbsd.org
Subject: PFIL_HOOKS doesn't always load PFIL_OUT hooks in the correct order
X-Send-Pr-Version: 3.95

>Number:         7802
>Category:       kern
>Synopsis:       PFIL_HOOKS doesn't always load PFIL_OUT hooks in the correct order
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jun 17 19:20:00 +0000 1999
>Closed-Date:    Fri Jun 18 06:04:06 +0000 1999
>Last-Modified:  Fri Jun 18 06:04:29 +0000 1999
>Originator:     Mike Pelley
>Release:        NetBSD 1.4
>Organization:
	Worldmap.Net
>Environment:
System: NetBSD rossem 1.4 NetBSD 1.4 (ROSSEM) #1: Mon May 31 21:09:01 EDT 1999 mike@rossem:/usr/src-mike/sys/arch/i386/compile/ROSSEM i386


>Description:
In pfil.c, the function pfil_list_add has the following section:

    if (flags & PFIL_IN)
        TAILQ_INSERT_HEAD(list, pfh, pfil_link);
    else
        TAILQ_INSERT_TAIL(list, pfh, pfil_link);

which is called from the function pfil_add_hook from the following section:

    if (flags & PFIL_IN)
        pfil_list_add(&pfil_in_list, func, flags);
    if (flags & PFIL_OUT)
        pfil_list_add(&pfil_out_list, func, flags);

In ip_fil.c (IPFilter), pfil_add_hook is called as follows:

    pfil_add_hook((void *)fr_check, PFIL_IN|PFIL_OUT);

This means that pfil_add_hook is set to PFIL_IN|PFIL_OUT, and pfil_add_hook
calls pfil_list_add twice.  However, since flags contains both PFIL_IN and
PFIL_OUT, the second call to pfil_list_add will still match the (flags &
PFIL_IN) and so add the hook to the top of the out queue, instead of the
bottom of the out queue as intended.

>How-To-Repeat:
Add another pseudo device that uses pfil_add_hook with both PFIL_IN and PFIL_OUT and notice that the order promised in the history section of pfil(9) is not followed.

>Fix:
This is a simple patch:

--- sys/net/pfil.c      Thu Mar 19 10:45:30 1998
+++ sys-mike/net/pfil.c Thu Jun 17 18:55:37 1999
@@ -79,9 +79,9 @@
                pfil_init();

        if (flags & PFIL_IN)
-               pfil_list_add(&pfil_in_list, func, flags);
+               pfil_list_add(&pfil_in_list, func, PFIL_IN);
        if (flags & PFIL_OUT)
-               pfil_list_add(&pfil_out_list, func, flags);
+               pfil_list_add(&pfil_out_list, func, PFIL_OUT);
 }

 static void
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: mrg 
State-Changed-When: Thu Jun 17 23:04:06 PDT 1999 
State-Changed-Why:  
patch applied. 
thanks 

From: christos@zoulas.com (Christos Zoulas)
To: mike@pelley.com, kern-bug-people@netbsd.org, gnats-bugs@gnats.netbsd.org,
        gnats@netbsd.org (GNATS Management)
Cc:  Subject: Re: kern/7802: PFIL_HOOKS doesn't always load PFIL_OUT hooks in the correct order
Date: Fri, 18 Jun 1999 01:49:49 -0400

 On Jun 17, 10:05pm, mike@pelley.com (mike@pelley.com) wrote:
 -- Subject: kern/7802: PFIL_HOOKS doesn't always load PFIL_OUT hooks in the c

 | >Fix:
 | This is a simple patch:
 | 
 | --- sys/net/pfil.c      Thu Mar 19 10:45:30 1998
 | +++ sys-mike/net/pfil.c Thu Jun 17 18:55:37 1999
 | @@ -79,9 +79,9 @@
 |                 pfil_init();
 |  
 |         if (flags & PFIL_IN)
 | -               pfil_list_add(&pfil_in_list, func, flags);
 | +               pfil_list_add(&pfil_in_list, func, PFIL_IN);
 |         if (flags & PFIL_OUT)
 | -               pfil_list_add(&pfil_out_list, func, flags);
 | +               pfil_list_add(&pfil_out_list, func, PFIL_OUT);
 |  }
 |  
 |  static void
 | >Audit-Trail:
 | >Unformatted:
 -- End of excerpt from mike@pelley.com

 Better:
        pfil_list_add(&pfil_out_list, func, flags & (PFIL_IN|PFIL_OUT));

 christos


From: "Mike Pelley" <mikep@winddance.net>
To: "Christos Zoulas" <christos@zoulas.com>,
	<kern-bug-people@netbsd.org>,
	<gnats-bugs@gnats.netbsd.org>,
	"GNATS Management" <gnats@netbsd.org>
Cc:  Subject: Re: kern/7802: PFIL_HOOKS doesn't always load PFIL_OUT hooks in the correct order
Date: Fri, 18 Jun 1999 09:07:14 -0400

 > Better:
 >        pfil_list_add(&pfil_out_list, func, flags & (PFIL_IN|PFIL_OUT));
 > 
 > christos

 Actually, this would defeat the purpose of the patch I believe...  ;o)

 Mike.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.