Skip to content

Commit

Permalink
cfg80211: preserve wdev ID across netns changes
Browse files Browse the repository at this point in the history
When a wdev changes network namespace, its wdev ID will get
reassigned since NETDEV_REGISTER is called again, in the new
network namespace. Avoid that by checking if it was already
assigned before, and document why we do that.

Reported-and-tested-by: Arend Van Spriel <[email protected]>
Signed-off-by: Johannes Berg <[email protected]>
  • Loading branch information
jmberg authored and jmberg-intel committed Mar 17, 2017
1 parent 335d534 commit b6ecfd4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion net/wireless/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,15 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
INIT_LIST_HEAD(&wdev->mgmt_registrations);
spin_lock_init(&wdev->mgmt_registrations_lock);

wdev->identifier = ++rdev->wdev_id;
/*
* We get here also when the interface changes network namespaces,
* as it's registered into the new one, but we don't want it to
* change ID in that case. Checking if the ID is already assigned
* works, because 0 isn't considered a valid ID and the memory is
* 0-initialized.
*/
if (!wdev->identifier)
wdev->identifier = ++rdev->wdev_id;
list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list);
rdev->devlist_generation++;
/* can only change netns with wiphy */
Expand Down

0 comments on commit b6ecfd4

Please sign in to comment.