From: Johannes Berg <johannes@sipsolutions.net>
To: John Linville <linville@tuxdriver.com>
Cc: linux-wireless <linux-wireless@vger.kernel.org>,
Bas Hulsken <bhulsken@zonnet.nl>,
Larry Finger <Larry.Finger@lwfinger.net>,
Stefano Brivio <stefano.brivio@polimi.it>
Subject: [PATCH] mac80211: fix scan band off-by-one error
Date: Mon, 28 Jan 2008 17:08:56 +0100 [thread overview]
Message-ID: <1201536536.9397.12.camel@johannes.berg> (raw)
When checking for the next band to advance to, there
was an off-by-one error that could lead to an access
to an invalid array index. Additionally, the later
check for scan_band >= IEEE80211_NUM_BANDS is not
required since that will never be true.
This also improves the comments related to that code.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
---
This should fix the problem with the sband pointer access
crashing later. The next item right after the bands[]
array is a spinlock in "struct device" which happens to
be unlocked and hence, on powerpc, initialised to zero
which meant sband was NULL for me, while it's *one* on
x86 so sband is non-NULL leading to the crash.
Sorry about the mess.
net/mac80211/ieee80211_sta.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
--- everything.orig/net/mac80211/ieee80211_sta.c 2008-01-28 16:42:03.754363986 +0100
+++ everything/net/mac80211/ieee80211_sta.c 2008-01-28 17:04:57.654297255 +0100
@@ -3223,22 +3223,28 @@ void ieee80211_sta_scan_work(struct work
switch (local->scan_state) {
case SCAN_SET_CHANNEL:
- /* get current scan band */
+ /*
+ * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
+ * after we successfully scanned the last channel of the last
+ * band (and the last band is supported by the hw)
+ */
if (local->scan_band < IEEE80211_NUM_BANDS)
sband = local->hw.wiphy->bands[local->scan_band];
else
sband = NULL;
- /* if we started at an unsupported one, advance */
- while (!sband && local->scan_band < IEEE80211_NUM_BANDS) {
+ /*
+ * If we are at an unsupported band and have more bands
+ * left to scan, advance to the next supported one.
+ */
+ while (!sband && local->scan_band < IEEE80211_NUM_BANDS - 1) {
local->scan_band++;
sband = local->hw.wiphy->bands[local->scan_band];
local->scan_channel_idx = 0;
}
- if (!sband ||
- (local->scan_channel_idx >= sband->n_channels &&
- local->scan_band >= IEEE80211_NUM_BANDS)) {
+ /* if no more bands/channels left, complete scan */
+ if (!sband || local->scan_channel_idx >= sband->n_channels) {
ieee80211_scan_completed(local_to_hw(local));
return;
}
@@ -3260,8 +3266,14 @@ void ieee80211_sta_scan_work(struct work
}
}
+ /* advance state machine to next channel/band */
local->scan_channel_idx++;
if (local->scan_channel_idx >= sband->n_channels) {
+ /*
+ * scan_band may end up == IEEE80211_NUM_BANDS, but
+ * we'll catch that case above and complete the scan
+ * if that is the case.
+ */
local->scan_band++;
local->scan_channel_idx = 0;
}
reply other threads:[~2008-01-29 11:28 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1201536536.9397.12.camel@johannes.berg \
--to=johannes@sipsolutions.net \
--cc=Larry.Finger@lwfinger.net \
--cc=bhulsken@zonnet.nl \
--cc=linux-wireless@vger.kernel.org \
--cc=linville@tuxdriver.com \
--cc=stefano.brivio@polimi.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox