Moving a netdev to another namespace unregisters and re-registers its wireless_dev at the head of wdev_list. When a later move or wiphy rename fails, the reverse undo walk restores its first entry, which is again reinserted at the head. The walk then reaches the list head and skips other interfaces that were already moved. The wiphy may remain in the old namespace while those interfaces remain in the new one. Keep the failed entry as the undo boundary and walk forward with a cached next pointer. This restores each successful move once despite notifier-driven list changes and leaves the failed and unvisited entries alone. Fixes: 463d01832385 ("cfg80211: make aware of net namespaces") Signed-off-by: Baek Kyu, Kim --- On arm64 QEMU/KVM with mac80211_hwsim and an injected -ENOMEM at an interface move or wiphy rename boundary, the original 7.4-rc5 kernel failed rollback in five of eleven completed cases. The changed kernel restored all moved interfaces in all eleven. A hook-free image passed four normal movement and teardown cases. These runs used down virtual interfaces; real allocation failures and physical Wi-Fi devices were not tested. net/wireless/core.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/net/wireless/core.c b/net/wireless/core.c index 4e39db0c595c..cba215215862 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -168,7 +168,7 @@ static int __cfg80211_switch_netns(struct cfg80211_registered_device *rdev, struct net *net, bool force) { struct net *old_net = wiphy_net(&rdev->wiphy); - struct wireless_dev *wdev, *tmp; + struct wireless_dev *wdev, *tmp, *stop; int err = 0; /* make the whole switch atomic for cfg80211_mutex holders, e.g. dumps */ @@ -218,16 +218,20 @@ static int __cfg80211_switch_netns(struct cfg80211_registered_device *rdev, if (!err || force) return err; - /* set to the last one to undo all of them */ + /* use the list head as the undo boundary */ wdev = list_entry(&rdev->wiphy.wdev_list, typeof(*wdev), list); undo: /* - * Move back everything, if this fails again (allocation failures) - * then things get stuck in different network namespaces. + * Move back previously moved interfaces. Moving a netdev reinserts + * its wdev at the list head, so cache the next entry before moving it. + * If undo fails, interfaces may remain in different namespaces. */ - list_for_each_entry_continue_reverse(wdev, &rdev->wiphy.wdev_list, - list) + stop = wdev; + list_for_each_entry_safe(wdev, tmp, &rdev->wiphy.wdev_list, list) { + if (wdev == stop) + break; WARN_ON(cfg80211_switch_wdev_netns(wdev, old_net)); + } return err; } -- 2.55.0