Search Linux Wireless

[PATCH 05/18] mac80211: fix work race

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When we stop an interface, the work on it may still be pending
or running. We do cancel the timer, but we do not currently
protect against the work struct. The race is very unlikely to
hit -- it'll happen only when the driver is using mac80211's
workqueue to run long-running tasks and the sta/mesh works are
delayed for quite a bit.

This patch fixes it by cancelling the work explicitly.

Signed-off-by: Johannes Berg <johannes@xxxxxxxxxxxxxxxx>
---
 net/mac80211/main.c |    8 ++++++++
 net/mac80211/mesh.c |    9 +++++++++
 2 files changed, 17 insertions(+)

--- everything.orig/net/mac80211/main.c	2008-09-10 23:57:55.000000000 +0200
+++ everything/net/mac80211/main.c	2008-09-10 23:57:57.000000000 +0200
@@ -548,6 +548,14 @@ static int ieee80211_stop(struct net_dev
 		memset(sdata->u.sta.bssid, 0, ETH_ALEN);
 		del_timer_sync(&sdata->u.sta.timer);
 		/*
+		 * If the timer fired while we waited for it, it will have
+		 * requeued the work. Now the work will be running again
+		 * but will not rearm the timer again because it checks
+		 * whether the interface is running, which, at this point,
+		 * it no longer is.
+		 */
+		cancel_work_sync(&sdata->u.sta.work);
+		/*
 		 * When we get here, the interface is marked down.
 		 * Call synchronize_rcu() to wait for the RX path
 		 * should it be using the interface and enqueuing
--- everything.orig/net/mac80211/mesh.c	2008-09-10 23:57:55.000000000 +0200
+++ everything/net/mac80211/mesh.c	2008-09-10 23:57:57.000000000 +0200
@@ -449,6 +449,15 @@ void ieee80211_stop_mesh(struct ieee8021
 {
 	del_timer_sync(&sdata->u.mesh.housekeeping_timer);
 	/*
+	 * If the timer fired while we waited for it, it will have
+	 * requeued the work. Now the work will be running again
+	 * but will not rearm the timer again because it checks
+	 * whether the interface is running, which, at this point,
+	 * it no longer is.
+	 */
+	cancel_work_sync(&sdata->u.mesh.work);
+
+	/*
 	 * When we get here, the interface is marked down.
 	 * Call synchronize_rcu() to wait for the RX path
 	 * should it be using the interface and enqueuing

-- 

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

[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux