[PATCH wireless-next 2/3] wifi: mac80211: Check link id at station removal
From: Remi Pommarel
Date: Fri Jun 27 2025 - 16:56:48 EST
hostapd can remove a non-MLD sta connected to one link of one MLD AP
several times. If the sta roamed to another link of the same MLD AP
between two of those removals the wrong sta_info could be removed.
To fix that remove sta only if it is currently using the link specified
in NL80211_CMD_DEL_STATION if they are any.
Signed-off-by: Remi Pommarel <repk@xxxxxxxxxxxx>
---
net/mac80211/cfg.c | 3 ++-
net/mac80211/sta_info.c | 7 ++++++-
net/mac80211/sta_info.h | 2 +-
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index d9d88f2f2831..3dfe8e0759bb 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -2195,7 +2195,8 @@ static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (params->mac)
- return sta_info_destroy_addr_bss(sdata, params->mac);
+ return sta_info_destroy_addr_bss(sdata, params->mac,
+ params->link_id);
sta_info_flush(sdata, params->link_id);
return 0;
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index 61583173629e..7e58ae507a14 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -1530,13 +1530,18 @@ int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata, const u8 *addr)
}
int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata,
- const u8 *addr)
+ const u8 *addr, int link_id)
{
struct sta_info *sta;
lockdep_assert_wiphy(sdata->local->hw.wiphy);
sta = sta_info_get_bss(sdata, addr);
+
+ if (sta && link_id >= 0 && sta->sta.valid_links &&
+ !(sta->sta.valid_links & BIT(link_id)))
+ return -EINVAL;
+
return __sta_info_destroy(sta);
}
diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h
index 7a95d8d34fca..653eda1c2466 100644
--- a/net/mac80211/sta_info.h
+++ b/net/mac80211/sta_info.h
@@ -878,7 +878,7 @@ int __must_check __sta_info_destroy(struct sta_info *sta);
int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata,
const u8 *addr);
int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata,
- const u8 *addr);
+ const u8 *addr, int link_id);
void sta_info_recalc_tim(struct sta_info *sta);
--
2.40.0