All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mac80211: handle failed scan requests in STA mode
@ 2009-03-09 14:47 Helmut Schaa
  2009-03-09 14:50 ` Johannes Berg
  2009-03-09 15:17 ` Helmut Schaa
  0 siblings, 2 replies; 5+ messages in thread
From: Helmut Schaa @ 2009-03-09 14:47 UTC (permalink / raw)
  To: linville; +Cc: linux-wireless, johannes

If cfg80211 requests a scan it awaits either a return code != 0 from
the scan function or the cfg80211_scan_done to be called. In case of
a STA mac80211's scan function ever returns 0 and queues the scan request.
If ieee80211_sta_work is executed and ieee80211_start_scan fails for
some reason cfg80211_scan_done will never be called but cfg80211 still
thinks the scan was triggered successfully and will refuse any future
scan requests due to drv->scan_req not being cleaned up.

If a scan is triggered from within the MLME a similar problem appears. If
ieee80211_start_scan returns an error, local->scan_req will not be reset
and mac80211 will refuse any future scan requests.

Hence, in both cases call ieee80211_scan_failed (which notifies cfg80211
and resets local->scan_req) if ieee80211_start_scan returns an error.

Signed-off-by: Helmut Schaa <helmut.schaa@googlemail.com>
---

It just happend to me that after rf-killing iwlwifi wpa_supplicant triggered
a scan (which was accepted by mac80211 as it is not rfkill aware yet) which
failed in iwlwifi and left cfg80211 in a state where it won't accept a new
scan request even after unkilling the radio again.

Johannes, do you think it is worth to add something like a scan watchdog that
triggers after 30 seconds to cfg80211 and prints "scan request failed", cancels
the scan request and notifies user space?

diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index ecbc8e0..fbb91f1 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -972,6 +972,7 @@ int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata,
 			       char *ie, size_t len);
 
 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local);
+void ieee80211_scan_failed(struct ieee80211_local *local);
 int ieee80211_start_scan(struct ieee80211_sub_if_data *scan_sdata,
 			 struct cfg80211_scan_request *req);
 struct ieee80211_bss *
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index eeb6da8..6e92674 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -1720,7 +1720,10 @@ static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata)
 				local->int_scan_req.ssids[0].ssid_len = 0;
 			else
 				local->int_scan_req.ssids[0].ssid_len = ifmgd->ssid_len;
-			ieee80211_start_scan(sdata, &local->int_scan_req);
+
+			if (ieee80211_start_scan(sdata, &local->int_scan_req))
+				ieee80211_scan_failed(local);
+
 			ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
 			set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
 		} else {
@@ -1757,7 +1760,14 @@ static void ieee80211_sta_work(struct work_struct *work)
 	    ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE &&
 	    ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE &&
 	    test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) {
-		ieee80211_start_scan(sdata, local->scan_req);
+		/*
+		 * The call to ieee80211_start_scan can fail but ieee80211_request_scan 
+		 * (which queued ieee80211_sta_work) did not return an error. Thus, call
+		 * ieee80211_scan_failed here if ieee80211_start_scan fails in order to
+		 * notify the scan requester.
+		 */
+		if (ieee80211_start_scan(sdata, local->scan_req))
+			ieee80211_scan_failed(local);
 		return;
 	}
 
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index 0e81e16..5030a3c 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -202,6 +202,18 @@ ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
 	return RX_QUEUED;
 }
 
+void ieee80211_scan_failed(struct ieee80211_local *local)
+{
+	if (WARN_ON(!local->scan_req))
+		return;
+
+	/* notify cfg80211 about the failed scan */
+	if (local->scan_req != &local->int_scan_req)
+		cfg80211_scan_done(local->scan_req, true);
+
+	local->scan_req = NULL;
+}
+
 void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
 {
 	struct ieee80211_local *local = hw_to_local(hw);

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mac80211: handle failed scan requests in STA mode
  2009-03-09 14:47 [PATCH] mac80211: handle failed scan requests in STA mode Helmut Schaa
@ 2009-03-09 14:50 ` Johannes Berg
  2009-03-09 15:03   ` Helmut Schaa
  2009-03-09 15:17 ` Helmut Schaa
  1 sibling, 1 reply; 5+ messages in thread
From: Johannes Berg @ 2009-03-09 14:50 UTC (permalink / raw)
  To: Helmut Schaa; +Cc: linville, linux-wireless

[-- Attachment #1: Type: text/plain, Size: 1588 bytes --]

On Mon, 2009-03-09 at 15:47 +0100, Helmut Schaa wrote:
> If cfg80211 requests a scan it awaits either a return code != 0 from
> the scan function or the cfg80211_scan_done to be called. In case of
> a STA mac80211's scan function ever returns 0 and queues the scan request.
> If ieee80211_sta_work is executed and ieee80211_start_scan fails for
> some reason cfg80211_scan_done will never be called but cfg80211 still
> thinks the scan was triggered successfully and will refuse any future
> scan requests due to drv->scan_req not being cleaned up.
> 
> If a scan is triggered from within the MLME a similar problem appears. If
> ieee80211_start_scan returns an error, local->scan_req will not be reset
> and mac80211 will refuse any future scan requests.
> 
> Hence, in both cases call ieee80211_scan_failed (which notifies cfg80211
> and resets local->scan_req) if ieee80211_start_scan returns an error.

This patch looks good.

> Signed-off-by: Helmut Schaa <helmut.schaa@googlemail.com>
> ---
> 
> It just happend to me that after rf-killing iwlwifi wpa_supplicant triggered
> a scan (which was accepted by mac80211 as it is not rfkill aware yet) which
> failed in iwlwifi and left cfg80211 in a state where it won't accept a new
> scan request even after unkilling the radio again.
> 
> Johannes, do you think it is worth to add something like a scan watchdog that
> triggers after 30 seconds to cfg80211 and prints "scan request failed", cancels
> the scan request and notifies user space?

But I don't really think it's worth doing that.

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mac80211: handle failed scan requests in STA mode
  2009-03-09 14:50 ` Johannes Berg
@ 2009-03-09 15:03   ` Helmut Schaa
  2009-03-09 15:07     ` Johannes Berg
  0 siblings, 1 reply; 5+ messages in thread
From: Helmut Schaa @ 2009-03-09 15:03 UTC (permalink / raw)
  To: Johannes Berg; +Cc: linville, linux-wireless

Am Montag, 9. M=E4rz 2009 schrieb Johannes Berg:
> On Mon, 2009-03-09 at 15:47 +0100, Helmut Schaa wrote:
> > Johannes, do you think it is worth to add something like a scan wat=
chdog that
> > triggers after 30 seconds to cfg80211 and prints "scan request fail=
ed", cancels
> > the scan request and notifies user space?
>=20
> But I don't really think it's worth doing that.

=46ine with me. This was just a quick idea on how we could easily spot =
such=20
bugs in the future (for example when fullmac drivers start using cfg802=
11).

Helmut
--
To unsubscribe from this list: send the line "unsubscribe linux-wireles=
s" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mac80211: handle failed scan requests in STA mode
  2009-03-09 15:03   ` Helmut Schaa
@ 2009-03-09 15:07     ` Johannes Berg
  0 siblings, 0 replies; 5+ messages in thread
From: Johannes Berg @ 2009-03-09 15:07 UTC (permalink / raw)
  To: Helmut Schaa; +Cc: linville, linux-wireless

[-- Attachment #1: Type: text/plain, Size: 740 bytes --]

On Mon, 2009-03-09 at 16:03 +0100, Helmut Schaa wrote:
> Am Montag, 9. März 2009 schrieb Johannes Berg:
> > On Mon, 2009-03-09 at 15:47 +0100, Helmut Schaa wrote:
> > > Johannes, do you think it is worth to add something like a scan watchdog that
> > > triggers after 30 seconds to cfg80211 and prints "scan request failed", cancels
> > > the scan request and notifies user space?
> > 
> > But I don't really think it's worth doing that.
> 
> Fine with me. This was just a quick idea on how we could easily spot such 
> bugs in the future (for example when fullmac drivers start using cfg80211).

Yeah, might be worth it later, but I suspect that other drivers will
have state machines that are easier to verify.

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mac80211: handle failed scan requests in STA mode
  2009-03-09 14:47 [PATCH] mac80211: handle failed scan requests in STA mode Helmut Schaa
  2009-03-09 14:50 ` Johannes Berg
@ 2009-03-09 15:17 ` Helmut Schaa
  1 sibling, 0 replies; 5+ messages in thread
From: Helmut Schaa @ 2009-03-09 15:17 UTC (permalink / raw)
  To: linville; +Cc: linux-wireless, johannes

Am Montag, 9. M=E4rz 2009 schrieb Helmut Schaa:
> If cfg80211 requests a scan it awaits either a return code !=3D 0 fro=
m
> the scan function or the cfg80211_scan_done to be called. In case of
> a STA mac80211's scan function ever returns 0 and queues the scan req=
uest.
> If ieee80211_sta_work is executed and ieee80211_start_scan fails for
> some reason cfg80211_scan_done will never be called but cfg80211 stil=
l
> thinks the scan was triggered successfully and will refuse any future
> scan requests due to drv->scan_req not being cleaned up.
>=20
> If a scan is triggered from within the MLME a similar problem appears=
=2E If
> ieee80211_start_scan returns an error, local->scan_req will not be re=
set
> and mac80211 will refuse any future scan requests.
>=20
> Hence, in both cases call ieee80211_scan_failed (which notifies cfg80=
211
> and resets local->scan_req) if ieee80211_start_scan returns an error.
>=20
> Signed-off-by: Helmut Schaa <helmut.schaa@googlemail.com>

Btw, John, I guess this should go into linux-next as the cfg80211-scan =
code
is there already and otherwise cfg80211 and mac80211 can get stuck (ref=
uses
any scan requests) when the iwlwifi killswitch is used (only tested wit=
h
NetworkManager).

I'm not sure if anything apart from the killswitch also triggers this i=
ssue.

Thanks,
Helmut
--
To unsubscribe from this list: send the line "unsubscribe linux-wireles=
s" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-03-09 15:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-09 14:47 [PATCH] mac80211: handle failed scan requests in STA mode Helmut Schaa
2009-03-09 14:50 ` Johannes Berg
2009-03-09 15:03   ` Helmut Schaa
2009-03-09 15:07     ` Johannes Berg
2009-03-09 15:17 ` Helmut Schaa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.