wifi: mac80211: enforce IBSS station allocation limits
Subsystems (2)
cover wifi: mac80211: enforce IBSS station allocation limits
Patch 1 prevents the worker from installing more than 128 stations. Patch 2 bounds pending station allocations to 128 per interface. The patches are ordered: the insertion recheck must precede the pending-allocation bound.
LLM assistance was used to review this series.
Zhao Li (2):
wifi: mac80211: recheck the IBSS station limit before insertion
wifi: mac80211: bound pending IBSS station allocations
net/mac80211/ibss.c | 21 ++++++++++++++++++--- net/mac80211/ieee80211_i.h | 1 + 2 files changed, 19 insertions(+), 3 deletions(-)
base-commit: 25e73f1d6868c759c8eb56cad4e411692c5341b4
Signature · 1 line
2.56.0
PATCH 1/2 wifi: mac80211: recheck the IBSS station limit before insertion
Frames from successive unknown IBSS peers can make the deferred worker install more than 128 stations.
The receive path checks local->num_sta before allocating each station, but pending stations are not included in that count. Several allocations can therefore pass before the worker inserts any of them, and the worker then drains the list without rechecking the limit.
Recheck the installed-station limit in the worker under the wiphy mutex and free entries that no longer fit.
LLM assistance was used to find the bug and review.
---
Validation: A W=1 module build with MODPOST passed. The insertion recheck was not exercised separately; the two-patch series was run as described in patch 2. A reproducer is available on request. Sparse C=2 passed. Targeted Smatch introduced no new diagnostics.
net/mac80211/ibss.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
net/mac80211/ibss.c +6 -2
@@ -1626,8 +1626,12 @@ void ieee80211_ibss_work(struct ieee80211_sub_if_data *sdata)list_del (&sta->list);spin_unlock_bh (&ifibss->incomplete_lock); -ieee80211_ibss_finish_sta (sta); -rcu_read_unlock (); +if (sdata->local->num_sta >=IEEE80211_IBSS_MAX_STA_ENTRIES ) { +sta_info_free (sdata->local, sta); + }else { +ieee80211_ibss_finish_sta (sta); +rcu_read_unlock (); + }spin_lock_bh (&ifibss->incomplete_lock); }spin_unlock_bh (&ifibss->incomplete_lock);
Signature · 1 line
2.56.0
PATCH 2/2 wifi: mac80211: bound pending IBSS station allocations
In reply to Zhao LiDelaying the IBSS station worker while frames arrive from new peers can retain an unbounded number of station allocations.
The receive-side limit counts installed stations, while new allocations wait on incomplete_stations until process context inserts them. The list lock does not cover the interval between allocation and list insertion.
Reserve one of 128 pending slots per interface before allocation. Release the reservation on allocation failure, after the worker inserts or frees the station, and when disconnect frees the pending list.
LLM assistance was used to find the bug and review.
---
Validation: A W=1 module build with MODPOST passed. In a QEMU hwsim guest, a 2048-address flood left 293 IBSS stations before the series and 128 after it, with no KASAN report. This is a resource bound, not a memory-safety result. A reproducer is available on request. Sparse C=2 passed. Targeted Smatch introduced no new diagnostics.
net/mac80211/ibss.c | 13 ++++++++++++- net/mac80211/ieee80211_i.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-)
net/mac80211/ibss.c +12 -1
@@ -680,6 +680,7 @@ static void ieee80211_ibss_disconnect(struct ieee80211_sub_if_data *sdata)spin_unlock_bh (&ifibss->incomplete_lock);sta_info_free (local, sta); +atomic_dec (&ifibss->incomplete_sta_count);spin_lock_bh (&ifibss->incomplete_lock); }spin_unlock_bh (&ifibss->incomplete_lock);
@@ -1173,9 +1174,18 @@ void ieee80211_ibss_rx_no_sta(struct ieee80211_sub_if_data *sdata, band = chanctx_conf->def.chan->band;rcu_read_unlock (); +if (!atomic_add_unless (&ifibss->incomplete_sta_count,1 , +IEEE80211_IBSS_MAX_STA_ENTRIES )) { +net_info_ratelimited ("%s: No room for a new IBSS STA entry %pM\n" , + sdata->name, addr); +return ; + } + sta =sta_info_alloc (sdata, addr,GFP_ATOMIC ); -if (!sta) +if (!sta) { +atomic_dec (&ifibss->incomplete_sta_count);return ; + }/* make sure mandatory rates are always added */ sband = local->hw.wiphy->bands[band];
@@ -1632,6 +1642,7 @@ void ieee80211_ibss_work(struct ieee80211_sub_if_data *sdata)ieee80211_ibss_finish_sta (sta);rcu_read_unlock (); } +atomic_dec (&ifibss->incomplete_sta_count);spin_lock_bh (&ifibss->incomplete_lock); }spin_unlock_bh (&ifibss->incomplete_lock);
net/mac80211/ieee80211_i.h +1 -0
@@ -682,6 +682,7 @@ struct ieee80211_if_ibss {spinlock_t incomplete_lock;struct list_head incomplete_stations; +atomic_t incomplete_sta_count;enum {IEEE80211_IBSS_MLME_SEARCH ,
Signature · 1 line
2.56.0