aboutsummaryrefslogtreecommitdiff
path: root/sys/net80211
diff options
context:
space:
mode:
authorChristian S.J. Peron <csjp@FreeBSD.org>2006-06-02 19:59:33 +0000
committerChristian S.J. Peron <csjp@FreeBSD.org>2006-06-02 19:59:33 +0000
commit16d878cc99efc07781a49b1db1a33ed09018d139 (patch)
tree91b5bc64ab856cef269d9fab6ff3feca3e06cf2c /sys/net80211
parent6dea56bafccc28232dbef53d74a1683568c7c516 (diff)
downloadsrc-16d878cc99efc07781a49b1db1a33ed09018d139.tar.gz
src-16d878cc99efc07781a49b1db1a33ed09018d139.zip
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
Notes
Notes: svn path=/head/; revision=159180
Diffstat (limited to 'sys/net80211')
-rw-r--r--sys/net80211/ieee80211_input.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/sys/net80211/ieee80211_input.c b/sys/net80211/ieee80211_input.c
index 33a462150929..e6a9676fdfbe 100644
--- a/sys/net80211/ieee80211_input.c
+++ b/sys/net80211/ieee80211_input.c
@@ -422,7 +422,7 @@ ieee80211_input(struct ieee80211com *ic, struct mbuf *m,
}
/* copy to listener after decrypt */
- if (ic->ic_rawbpf)
+ if (bpf_peers_present(ic->ic_rawbpf))
bpf_mtap(ic->ic_rawbpf, m);
/*
@@ -536,7 +536,7 @@ ieee80211_input(struct ieee80211com *ic, struct mbuf *m,
wh = mtod(m, struct ieee80211_frame *);
wh->i_fc[1] &= ~IEEE80211_FC1_WEP;
}
- if (ic->ic_rawbpf)
+ if (bpf_peers_present(ic->ic_rawbpf))
bpf_mtap(ic->ic_rawbpf, m);
(*ic->ic_recv_mgmt)(ic, m, ni, subtype, rssi, rstamp);
m_freem(m);
@@ -563,7 +563,7 @@ err:
ifp->if_ierrors++;
out:
if (m != NULL) {
- if (ic->ic_rawbpf)
+ if (bpf_peers_present(ic->ic_rawbpf))
bpf_mtap(ic->ic_rawbpf, m);
m_freem(m);
}
@@ -719,7 +719,7 @@ ieee80211_deliver_data(struct ieee80211com *ic,
return;
out:
if (m != NULL) {
- if (ic->ic_rawbpf)
+ if (bpf_peers_present(ic->ic_rawbpf))
bpf_mtap(ic->ic_rawbpf, m);
m_freem(m);
}