From: Johannes Berg Date: Thu, 7 May 2009 12:23:01 +0000 (+0200) Subject: mac80211: fix scan channel race X-Git-Tag: v2.6.31-rc1~14^2~464^2~38 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=58905ca5b11a0ff3860f55b789cbbf052f7158a7;p=platform%2Fupstream%2Fkernel-adaptation-pc.git mac80211: fix scan channel race When a software scan starts, it first sets sw_scanning, but leaves the scan_channel "unset" (it currently actually gets initialised to a default). Now, when something else tries to (re)configure the hardware in the window between these two events (after sw_scanning = true, but before scan_channel is set), the current code switches to the (unset!) scan_channel. This causes trouble, especially when switching bands and sending frames on the wrong channel. To work around this, leave scan_channel initialised to NULL and use it to determine whether or not a switch to a different channel should occur (and also use the same condition to check whether to adjust power for scan or not). Additionally, avoid reconfiguring the hardware completely when recalculating idle resulted in no changes, this was the problem that originally led us to discover the race condition in the first place, which was helpfully bisected by Pavel. This part of the patch should not be necessary with the other fixes, but not calling the ieee80211_hw_config function when we know it to be unnecessary is certainly a correct thing to do. Unfortunately, this patch cannot and does not fix the race condition completely, but due to the way the scan code is structured it makes the particular problem Pavel discovered (race while changing channel at the same time as transmitting frames) go away. To fix it completely, more work especially with locking configuration is needed. Bisected-by: Pavel Roskin Signed-off-by: Johannes Berg Signed-off-by: John W. Linville --- diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c index 8b6daf0..8c9f1c7 100644 --- a/net/mac80211/iface.c +++ b/net/mac80211/iface.c @@ -964,5 +964,6 @@ void ieee80211_recalc_idle(struct ieee80211_local *local) mutex_lock(&local->iflist_mtx); chg = __ieee80211_recalc_idle(local); mutex_unlock(&local->iflist_mtx); - ieee80211_hw_config(local, chg); + if (chg) + ieee80211_hw_config(local, chg); } diff --git a/net/mac80211/main.c b/net/mac80211/main.c index b80bc80..76df5ea 100644 --- a/net/mac80211/main.c +++ b/net/mac80211/main.c @@ -154,15 +154,17 @@ static void ieee80211_master_set_multicast_list(struct net_device *dev) int ieee80211_hw_config(struct ieee80211_local *local, u32 changed) { - struct ieee80211_channel *chan; + struct ieee80211_channel *chan, *scan_chan; int ret = 0; int power; enum nl80211_channel_type channel_type; might_sleep(); - if (local->sw_scanning) { - chan = local->scan_channel; + scan_chan = local->scan_channel; + + if (scan_chan) { + chan = scan_chan; channel_type = NL80211_CHAN_NO_HT; } else { chan = local->oper_channel; @@ -176,7 +178,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed) changed |= IEEE80211_CONF_CHANGE_CHANNEL; } - if (local->sw_scanning) + if (scan_chan) power = chan->max_power; else power = local->power_constr_level ? @@ -859,8 +861,8 @@ int ieee80211_register_hw(struct ieee80211_hw *hw) if (!local->oper_channel) { /* init channel we're on */ local->hw.conf.channel = - local->oper_channel = - local->scan_channel = &sband->channels[0]; + local->oper_channel = &sband->channels[0]; + local->hw.conf.channel_type = NL80211_CHAN_NO_HT; } channels += sband->n_channels; diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c index c99ef8d..e51b99b 100644 --- a/net/mac80211/scan.c +++ b/net/mac80211/scan.c @@ -298,6 +298,7 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted) was_hw_scan = local->hw_scanning; local->hw_scanning = false; local->sw_scanning = false; + local->scan_channel = NULL; /* we only have to protect scan_req and hw/sw scan */ mutex_unlock(&local->scan_mtx);