freebsd-nq/sys/net
Christian S.J. Peron 16d878cc99 Fix the following bpf(4) race condition which can result in a panic:
(1) bpf peer attaches to interface netif0
	(2) Packet is received by netif0
	(3) ifp->if_bpf pointer is checked and handed off to bpf
	(4) bpf peer detaches from netif0 resulting in ifp->if_bpf being
	    initialized to NULL.
	(5) ifp->if_bpf is dereferenced by bpf machinery
	(6) Kaboom

This race condition likely explains the various different kernel panics
reported around sending SIGINT to tcpdump or dhclient processes. But really
this race can result in kernel panics anywhere you have frequent bpf attach
and detach operations with high packet per second load.

Summary of changes:

- Remove the bpf interface's "driverp" member
- When we attach bpf interfaces, we now set the ifp->if_bpf member to the
  bpf interface structure. Once this is done, ifp->if_bpf should never be
  NULL. [1]
- Introduce bpf_peers_present function, an inline operation which will do
  a lockless read bpf peer list associated with the interface. It should
  be noted that the bpf code will pickup the bpf_interface lock before adding
  or removing bpf peers. This should serialize the access to the bpf descriptor
  list, removing the race.
- Expose the bpf_if structure in bpf.h so that the bpf_peers_present function
  can use it. This also removes the struct bpf_if; hack that was there.
- Adjust all consumers of the raw if_bpf structure to use bpf_peers_present

Now what happens is:

	(1) Packet is received by netif0
	(2) Check to see if bpf descriptor list is empty
	(3) Pickup the bpf interface lock
	(4) Hand packet off to process

From the attach/detach side:

	(1) Pickup the bpf interface lock
	(2) Add/remove from bpf descriptor list

Now that we are storing the bpf interface structure with the ifnet, there is
is no need to walk the bpf interface list to locate the correct bpf interface.
We now simply look up the interface, and initialize the pointer. This has a
nice side effect of changing a bpf interface attach operation from O(N) (where
N is the number of bpf interfaces), to O(1).

[1] From now on, we can no longer check ifp->if_bpf to tell us whether or
    not we have any bpf peers that might be interested in receiving packets.

In collaboration with:	sam@
MFC after:	1 month
2006-06-02 19:59:33 +00:00
..
bpf_compat.h
bpf_filter.c Avoid unwanted sign extension of indexed byte load in bpf code. 2006-05-28 20:00:02 +00:00
bpf_jitter.c
bpf_jitter.h
bpf.c Fix the following bpf(4) race condition which can result in a panic: 2006-06-02 19:59:33 +00:00
bpf.h Fix the following bpf(4) race condition which can result in a panic: 2006-06-02 19:59:33 +00:00
bpfdesc.h Fix the following bpf(4) race condition which can result in a panic: 2006-06-02 19:59:33 +00:00
bridgestp.c If we miss the LINK_UP event from the network interface then the bridge port 2006-03-06 02:28:41 +00:00
bsd_comp.c
ethernet.h
fddi.h
firewire.h
if_arc.h Use ANSI C function protypes and declarations for if_arcsubr. 2006-04-12 07:44:31 +00:00
if_arcsubr.c Use ANSI C function protypes and declarations for if_arcsubr. 2006-04-12 07:44:31 +00:00
if_arp.h
if_atm.h
if_atmsubr.c
if_bridge.c Fix style(9) nits, whitespace and parentheses. 2006-05-16 22:50:41 +00:00
if_bridgevar.h If we miss the LINK_UP event from the network interface then the bridge port 2006-03-06 02:28:41 +00:00
if_clone.c
if_clone.h
if_disc.c Fix the following bpf(4) race condition which can result in a panic: 2006-06-02 19:59:33 +00:00
if_dl.h
if_ef.c
if_ethersubr.c Unbreak byte counters when network interfaces are in monitor mode by 2006-03-03 17:21:08 +00:00
if_faith.c
if_fddisubr.c
if_fwsubr.c
if_gif.c Fix the following bpf(4) race condition which can result in a panic: 2006-06-02 19:59:33 +00:00
if_gif.h
if_gre.c Fix the following bpf(4) race condition which can result in a panic: 2006-06-02 19:59:33 +00:00
if_gre.h
if_iso88025subr.c
if_llc.h
if_loop.c Fix the following bpf(4) race condition which can result in a panic: 2006-06-02 19:59:33 +00:00
if_media.c - Introduce ifmedia_baudrate(), which returns correct baudrate of the 2006-02-14 12:10:03 +00:00
if_media.h - Add definition for IFM_10G_CX4. 2006-06-02 07:50:58 +00:00
if_mib.c
if_mib.h
if_ppp.c Add IFF_NEEDSGIANT to kernel PPP support. I have no idea why this wasn't 2006-03-30 08:18:27 +00:00
if_ppp.h
if_pppvar.h
if_sl.c Fix the following bpf(4) race condition which can result in a panic: 2006-06-02 19:59:33 +00:00
if_slvar.h
if_sppp.h
if_spppfr.c
if_spppsubr.c
if_stf.c Fix the following bpf(4) race condition which can result in a panic: 2006-06-02 19:59:33 +00:00
if_stf.h
if_tap.c Revert the (int *) -> (intptr_t *) conversion done as part of rev. 1.59 2006-05-30 20:08:12 +00:00
if_tap.h
if_tapvar.h
if_tun.c Fix the following bpf(4) race condition which can result in a panic: 2006-06-02 19:59:33 +00:00
if_tun.h
if_types.h
if_var.h
if_vlan_var.h
if_vlan.c Don't acquire a lock before calling vlan_unconfig(). 2006-03-09 14:42:51 +00:00
if.c Announce all interfaces to devd on attach/detach. This adds a new devctl 2006-06-01 00:41:07 +00:00
if.h Remove various bits of conditional Alpha code and fixup a few comments. 2006-05-12 05:04:46 +00:00
iso88025.h
net_osdep.h Remove ip6fw. Since ipfw has full functional IPv6 support now and - in 2006-05-12 20:39:23 +00:00
netisr.c
netisr.h
pfil.c
pfil.h
pfkeyv2.h
ppp_comp.h
ppp_deflate.c This patch fixes a problem, which exists if you have IPSEC in your kernel 2006-02-27 16:56:22 +00:00
ppp_defs.h
ppp_tty.c
radix.c
radix.h
raw_cb.c raw_disconnect() now disconnects but does not detach the raw pcb. As a 2006-06-02 08:27:15 +00:00
raw_cb.h
raw_usrreq.c raw_disconnect() now disconnects but does not detach the raw pcb. As a 2006-06-02 08:27:15 +00:00
route.c The current routing code allows insertion of indirect routes that have 2006-05-16 19:11:11 +00:00
route.h - Fill in the correct rtm_index for RTM_ADD and RTM_CHANGE messages. 2006-03-15 19:39:09 +00:00
rtsock.c Chance protocol switch method pru_detach() so that it returns void 2006-04-01 15:42:02 +00:00
slcompress.c
slcompress.h
slip.h
zlib.c
zlib.h