* [PATCH] wifi: cfg80211: order the last wdev put before the wakeup
@ 2026-11-27 12:05 Nikolai Dokutovich
0 siblings, 0 replies; only message in thread
From: Nikolai Dokutovich @ 2026-11-27 12:05 UTC (permalink / raw)
To: johannes; +Cc: linux-wireless
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 <ndokutovich@gmail.com>
---
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-27 12:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 12:05 [PATCH] wifi: cfg80211: order the last wdev put before the wakeup Nikolai Dokutovich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox