cfg80211: fix locking regression in monitor channel tracking
authorJohannes Berg <johannes.berg@intel.com>
Wed, 4 Jul 2012 11:28:18 +0000 (13:28 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 4 Jul 2012 11:30:23 +0000 (13:30 +0200)
Michal's monitor channel tracking introduce a locking problem
as it locked the rdev lock inside the netdev notifier which
isn't allowed as we might already hold it if we get there by
removing an interface that is up.

Fix this by relying only on the RTNL to protect the interface
counters, the RTNL is always held in these code paths anyway.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
net/wireless/core.c
net/wireless/core.h

index e13365f1fa63d45ba70b5855b7efd0d1196214b5..eb60410ae58879b48c96d663f5926aaaaf1c47e9 100644 (file)
@@ -766,7 +766,7 @@ void cfg80211_update_iface_num(struct cfg80211_registered_device *rdev,
        bool has_monitors_only_old = cfg80211_has_monitors_only(rdev);
        bool has_monitors_only_new;
 
-       ASSERT_RDEV_LOCK(rdev);
+       ASSERT_RTNL();
 
        rdev->num_running_ifaces += num;
        if (iftype == NL80211_IFTYPE_MONITOR)
@@ -888,10 +888,8 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
                wdev->beacon_interval = 0;
                break;
        case NETDEV_DOWN:
-               dev_hold(dev);
-               cfg80211_lock_rdev(rdev);
                cfg80211_update_iface_num(rdev, wdev->iftype, -1);
-               cfg80211_unlock_rdev(rdev);
+               dev_hold(dev);
                queue_work(cfg80211_wq, &wdev->cleanup_work);
                break;
        case NETDEV_UP:
@@ -1001,9 +999,7 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
                mutex_unlock(&rdev->devlist_mtx);
                if (ret)
                        return notifier_from_errno(ret);
-               cfg80211_lock_rdev(rdev);
                cfg80211_update_iface_num(rdev, wdev->iftype, 1);
-               cfg80211_unlock_rdev(rdev);
                break;
        }
 
index 81fef3ddb5a8d83bc85d4e44c03994a6a6a7a5d8..377dc394f48c99ff1e4cec0df6929ebecc876649 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/debugfs.h>
 #include <linux/rfkill.h>
 #include <linux/workqueue.h>
+#include <linux/rtnetlink.h>
 #include <net/genetlink.h>
 #include <net/cfg80211.h>
 #include "reg.h"
@@ -56,6 +57,7 @@ struct cfg80211_registered_device {
 
        u32 ap_beacons_nlpid;
 
+       /* protected by RTNL only */
        int num_running_ifaces;
        int num_running_monitor_ifaces;
 
@@ -205,7 +207,7 @@ static inline void wdev_unlock(struct wireless_dev *wdev)
 
 static inline bool cfg80211_has_monitors_only(struct cfg80211_registered_device *rdev)
 {
-       ASSERT_RDEV_LOCK(rdev);
+       ASSERT_RTNL();
 
        return rdev->num_running_ifaces == rdev->num_running_monitor_ifaces &&
               rdev->num_running_ifaces > 0;