diff options
author | Johannes Berg <johannes@sipsolutions.net> | 2007-09-26 09:19:47 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-10-10 19:53:16 -0400 |
commit | 53918994b7c8c3bf0af5f641e1f299856799d883 (patch) | |
tree | 63338872613d3c08473acfb46c8a57490f85350b /net/mac80211 | |
parent | 50741ae05a4742cae99361f57d84b5f8d33822a4 (diff) |
[PATCH] mac80211: fix iff_promiscs, iff_allmultis race
When we update the counters iff_promiscs and iff_allmultis
in struct ieee80211_local we have no common lock held to
protect them. The problem is that the update to each counter
may not be atomic, so we could end up with iff_promiscs == -1
in unfortunate conditions. To fix it, use atomic_t values.
It doesn't matter whether the two counters are updated
together atomically or not, if there are two invocations
of set_multicast_list we will end up with multiple
configure_filter() invocations of which the latter will always
be correct.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'net/mac80211')
-rw-r--r-- | net/mac80211/ieee80211.c | 12 | ||||
-rw-r--r-- | net/mac80211/ieee80211_i.h | 5 | ||||
-rw-r--r-- | net/mac80211/rx.c | 3 |
3 files changed, 10 insertions, 10 deletions
diff --git a/net/mac80211/ieee80211.c b/net/mac80211/ieee80211.c index b1180536c335..2501bff0d15e 100644 --- a/net/mac80211/ieee80211.c +++ b/net/mac80211/ieee80211.c | |||
@@ -59,10 +59,10 @@ static void ieee80211_configure_filter(struct ieee80211_local *local) | |||
59 | unsigned int changed_flags; | 59 | unsigned int changed_flags; |
60 | unsigned int new_flags = 0; | 60 | unsigned int new_flags = 0; |
61 | 61 | ||
62 | if (local->iff_promiscs) | 62 | if (atomic_read(&local->iff_promiscs)) |
63 | new_flags |= FIF_PROMISC_IN_BSS; | 63 | new_flags |= FIF_PROMISC_IN_BSS; |
64 | 64 | ||
65 | if (local->iff_allmultis) | 65 | if (atomic_read(&local->iff_allmultis)) |
66 | new_flags |= FIF_ALLMULTI; | 66 | new_flags |= FIF_ALLMULTI; |
67 | 67 | ||
68 | if (local->monitors) | 68 | if (local->monitors) |
@@ -521,17 +521,17 @@ static void ieee80211_set_multicast_list(struct net_device *dev) | |||
521 | 521 | ||
522 | if (allmulti != sdata_allmulti) { | 522 | if (allmulti != sdata_allmulti) { |
523 | if (dev->flags & IFF_ALLMULTI) | 523 | if (dev->flags & IFF_ALLMULTI) |
524 | local->iff_allmultis++; | 524 | atomic_inc(&local->iff_allmultis); |
525 | else | 525 | else |
526 | local->iff_allmultis--; | 526 | atomic_dec(&local->iff_allmultis); |
527 | sdata->flags ^= IEEE80211_SDATA_ALLMULTI; | 527 | sdata->flags ^= IEEE80211_SDATA_ALLMULTI; |
528 | } | 528 | } |
529 | 529 | ||
530 | if (promisc != sdata_promisc) { | 530 | if (promisc != sdata_promisc) { |
531 | if (dev->flags & IFF_PROMISC) | 531 | if (dev->flags & IFF_PROMISC) |
532 | local->iff_promiscs++; | 532 | atomic_inc(&local->iff_promiscs); |
533 | else | 533 | else |
534 | local->iff_promiscs--; | 534 | atomic_dec(&local->iff_promiscs); |
535 | sdata->flags ^= IEEE80211_SDATA_PROMISC; | 535 | sdata->flags ^= IEEE80211_SDATA_PROMISC; |
536 | } | 536 | } |
537 | 537 | ||
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 32d19bbf522c..38e0a467fa8e 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h | |||
@@ -444,9 +444,8 @@ struct ieee80211_local { | |||
444 | struct ieee80211_tx_stored_packet pending_packet[NUM_TX_DATA_QUEUES]; | 444 | struct ieee80211_tx_stored_packet pending_packet[NUM_TX_DATA_QUEUES]; |
445 | struct tasklet_struct tx_pending_tasklet; | 445 | struct tasklet_struct tx_pending_tasklet; |
446 | 446 | ||
447 | int mc_count; /* total count of multicast entries in all interfaces */ | 447 | /* number of interfaces with corresponding IFF_ flags */ |
448 | int iff_allmultis, iff_promiscs; | 448 | atomic_t iff_allmultis, iff_promiscs; |
449 | /* number of interfaces with corresponding IFF_ flags */ | ||
450 | 449 | ||
451 | struct rate_control_ref *rate_ctrl; | 450 | struct rate_control_ref *rate_ctrl; |
452 | 451 | ||
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index 34adc5288fbc..03635fb3e9b6 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c | |||
@@ -1531,7 +1531,8 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, | |||
1531 | skb = rx.skb; | 1531 | skb = rx.skb; |
1532 | 1532 | ||
1533 | if (sta && !(sta->flags & (WLAN_STA_WDS | WLAN_STA_ASSOC_AP)) && | 1533 | if (sta && !(sta->flags & (WLAN_STA_WDS | WLAN_STA_ASSOC_AP)) && |
1534 | !local->iff_promiscs && !is_multicast_ether_addr(hdr->addr1)) { | 1534 | !atomic_read(&local->iff_promiscs) && |
1535 | !is_multicast_ether_addr(hdr->addr1)) { | ||
1535 | rx.flags |= IEEE80211_TXRXD_RXRA_MATCH; | 1536 | rx.flags |= IEEE80211_TXRXD_RXRA_MATCH; |
1536 | ieee80211_invoke_rx_handlers(local, local->rx_handlers, &rx, | 1537 | ieee80211_invoke_rx_handlers(local, local->rx_handlers, &rx, |
1537 | rx.sta); | 1538 | rx.sta); |