Skip to content

Commit

Permalink
cfg80211: pmsr: fix abort locking
Browse files Browse the repository at this point in the history
When we destroy the interface we already hold the wdev->mtx
while calling cfg80211_pmsr_wdev_down(), which assumes this
isn't true and flushes the worker that takes the lock, thus
leading to a deadlock.

Fix this by refactoring the worker and calling its code in
cfg80211_pmsr_wdev_down() directly.

We still need to flush the work later to make sure it's not
still running and will crash, but it will not do anything.

Fixes: 9bb7e0f ("cfg80211: add peer measurement with FTM initiator API")
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  • Loading branch information
Johannes Berg committed Feb 6, 2019
1 parent 0acd992 commit 7335042
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions net/wireless/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,8 @@ static void __cfg80211_unregister_wdev(struct wireless_dev *wdev, bool sync)

ASSERT_RTNL();

flush_work(&wdev->pmsr_free_wk);

nl80211_notify_iface(rdev, wdev, NL80211_CMD_DEL_INTERFACE);

list_del_rcu(&wdev->list);
Expand Down
22 changes: 15 additions & 7 deletions net/wireless/pmsr.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,14 +529,14 @@ void cfg80211_pmsr_report(struct wireless_dev *wdev,
}
EXPORT_SYMBOL_GPL(cfg80211_pmsr_report);

void cfg80211_pmsr_free_wk(struct work_struct *work)
static void cfg80211_pmsr_process_abort(struct wireless_dev *wdev)
{
struct wireless_dev *wdev = container_of(work, struct wireless_dev,
pmsr_free_wk);
struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
struct cfg80211_pmsr_request *req, *tmp;
LIST_HEAD(free_list);

lockdep_assert_held(&wdev->mtx);

spin_lock_bh(&wdev->pmsr_lock);
list_for_each_entry_safe(req, tmp, &wdev->pmsr_list, list) {
if (req->nl_portid)
Expand All @@ -546,14 +546,22 @@ void cfg80211_pmsr_free_wk(struct work_struct *work)
spin_unlock_bh(&wdev->pmsr_lock);

list_for_each_entry_safe(req, tmp, &free_list, list) {
wdev_lock(wdev);
rdev_abort_pmsr(rdev, wdev, req);
wdev_unlock(wdev);

kfree(req);
}
}

void cfg80211_pmsr_free_wk(struct work_struct *work)
{
struct wireless_dev *wdev = container_of(work, struct wireless_dev,
pmsr_free_wk);

wdev_lock(wdev);
cfg80211_pmsr_process_abort(wdev);
wdev_unlock(wdev);
}

void cfg80211_pmsr_wdev_down(struct wireless_dev *wdev)
{
struct cfg80211_pmsr_request *req;
Expand All @@ -567,8 +575,8 @@ void cfg80211_pmsr_wdev_down(struct wireless_dev *wdev)
spin_unlock_bh(&wdev->pmsr_lock);

if (found)
schedule_work(&wdev->pmsr_free_wk);
flush_work(&wdev->pmsr_free_wk);
cfg80211_pmsr_process_abort(wdev);

WARN_ON(!list_empty(&wdev->pmsr_list));
}

Expand Down

0 comments on commit 7335042

Please sign in to comment.