cfg80211_unregister_wdev() drops the registration reference on a wdev without a netdev and then waits in wait_var_event() for the count to reach zero while holding RTNL and the wiphy mutex. The last wdev_put() wakes it through wake_up_var() after refcount_dec_and_test(). wake_up_var() requires a full barrier between the store that makes the condition true and its waitqueue_active() check. refcount_dec_and_test() is release-ordered before the decrement and acquire-ordered after it, which orders prior accesses against the decrement and the decrement load against later accesses. Neither orders the decrement store against a later load of the waitqueue. So the last put can observe an empty waitqueue while the unregister, already queued, still reads a count of one. The unregister can then block indefinitely while holding RTNL and the wiphy mutex, stalling everything that takes RTNL as well as cfg80211 operations on that wiphy. x86 is safe because its locked xadd is a full barrier; arm64 and POWER are not. smp_mb__after_atomic() supplies the missing order and costs nothing on x86. Fixes: 13c20e8be327 ("wifi: nl80211: prepare for unlocked wdev-only ops") Signed-off-by: Nikolai Dokutovich --- net/wireless/core.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/net/wireless/core.h b/net/wireless/core.h index e70a4f679bf5..5f5144b36217 100644 --- a/net/wireless/core.h +++ b/net/wireless/core.h @@ -276,10 +276,17 @@ static inline void wdev_hold(struct wireless_dev *wdev) static inline void wdev_put(struct wireless_dev *wdev) { - if (wdev->netdev) + if (wdev->netdev) { dev_put(wdev->netdev); - else if (refcount_dec_and_test(&wdev->refcnt)) + } else if (refcount_dec_and_test(&wdev->refcnt)) { + /* + * wake_up_var() needs a full barrier between the store and its + * waitqueue check; refcount_dec_and_test() only orders the + * accesses around the decrement. + */ + smp_mb__after_atomic(); wake_up_var(&wdev->refcnt); + } } static inline bool cfg80211_has_monitors_only(struct cfg80211_registered_device *rdev) -- 2.43.0