Skip to content

Commit

Permalink
mac80211: fix virtual monitor interface locking
Browse files Browse the repository at this point in the history
The virtual monitor interface has a locking issue, it calls
into the channel context code with the iflist mutex held
which isn't allowed since it is usually acquired the other
way around. The mutex is still required for the interface
iteration, but need not be held across the channel calls.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  • Loading branch information
Johannes Berg committed Mar 20, 2013
1 parent ce1eadd commit 8b30578
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions net/mac80211/iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,21 +349,19 @@ static void ieee80211_set_default_queues(struct ieee80211_sub_if_data *sdata)
static int ieee80211_add_virtual_monitor(struct ieee80211_local *local)
{
struct ieee80211_sub_if_data *sdata;
int ret = 0;
int ret;

if (!(local->hw.flags & IEEE80211_HW_WANT_MONITOR_VIF))
return 0;

mutex_lock(&local->iflist_mtx);
ASSERT_RTNL();

if (local->monitor_sdata)
goto out_unlock;
return 0;

sdata = kzalloc(sizeof(*sdata) + local->hw.vif_data_size, GFP_KERNEL);
if (!sdata) {
ret = -ENOMEM;
goto out_unlock;
}
if (!sdata)
return -ENOMEM;

/* set up data */
sdata->local = local;
Expand All @@ -377,27 +375,28 @@ static int ieee80211_add_virtual_monitor(struct ieee80211_local *local)
if (WARN_ON(ret)) {
/* ok .. stupid driver, it asked for this! */
kfree(sdata);
goto out_unlock;
return ret;
}

ret = ieee80211_check_queues(sdata);
if (ret) {
kfree(sdata);
goto out_unlock;
return ret;
}

ret = ieee80211_vif_use_channel(sdata, &local->monitor_chandef,
IEEE80211_CHANCTX_EXCLUSIVE);
if (ret) {
drv_remove_interface(local, sdata);
kfree(sdata);
goto out_unlock;
return ret;
}

mutex_lock(&local->iflist_mtx);
rcu_assign_pointer(local->monitor_sdata, sdata);
out_unlock:
mutex_unlock(&local->iflist_mtx);
return ret;

return 0;
}

static void ieee80211_del_virtual_monitor(struct ieee80211_local *local)
Expand All @@ -407,23 +406,27 @@ static void ieee80211_del_virtual_monitor(struct ieee80211_local *local)
if (!(local->hw.flags & IEEE80211_HW_WANT_MONITOR_VIF))
return;

ASSERT_RTNL();

mutex_lock(&local->iflist_mtx);

sdata = rcu_dereference_protected(local->monitor_sdata,
lockdep_is_held(&local->iflist_mtx));
if (!sdata)
goto out_unlock;
if (!sdata) {
mutex_unlock(&local->iflist_mtx);
return;
}

rcu_assign_pointer(local->monitor_sdata, NULL);
mutex_unlock(&local->iflist_mtx);

synchronize_net();

ieee80211_vif_release_channel(sdata);

drv_remove_interface(local, sdata);

kfree(sdata);
out_unlock:
mutex_unlock(&local->iflist_mtx);
}

/*
Expand Down

0 comments on commit 8b30578

Please sign in to comment.