]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
wifi: mac80211: verify state before connection
authorMiri Korenblit <miriam.rachel.korenblit@intel.com>
Mon, 9 Jun 2025 18:35:15 +0000 (21:35 +0300)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 9 Jul 2025 09:52:35 +0000 (11:52 +0200)
ieee80211_prep_connection is supposed to be called when both bitmaps
(valid_links and active_links) are cleared.
Make sure of it and WARN if this is not the case, to avoid weird issues.

Signed-off-by: Miri Korenblit <miriam.rachel.korenblit@intel.com>
Reviewed-by: Johannes Berg <johannes.berg@intel.com>
Link: https://patch.msgid.link/20250609213231.f616c7b693df.Ie983155627ad0d2e7c19c30ce642915246d0ed9d@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
net/mac80211/mlme.c

index 6001c8897d7cbd3a175bc677679965ce18b6d099..41fd688d86a2593930440c14bbf1863e46549919 100644 (file)
@@ -8698,21 +8698,33 @@ static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
        bool have_sta = false;
        bool mlo;
        int err;
+       u16 new_links;
 
        if (link_id >= 0) {
                mlo = true;
                if (WARN_ON(!ap_mld_addr))
                        return -EINVAL;
-               err = ieee80211_vif_set_links(sdata, BIT(link_id), 0);
+               new_links = BIT(link_id);
        } else {
                if (WARN_ON(ap_mld_addr))
                        return -EINVAL;
                ap_mld_addr = cbss->bssid;
-               err = ieee80211_vif_set_links(sdata, 0, 0);
+               new_links = 0;
                link_id = 0;
                mlo = false;
        }
 
+       if (assoc) {
+               rcu_read_lock();
+               have_sta = sta_info_get(sdata, ap_mld_addr);
+               rcu_read_unlock();
+       }
+
+       if (mlo && !have_sta &&
+           WARN_ON(sdata->vif.valid_links || sdata->vif.active_links))
+               return -EINVAL;
+
+       err = ieee80211_vif_set_links(sdata, new_links, 0);
        if (err)
                return err;
 
@@ -8733,12 +8745,6 @@ static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
                goto out_err;
        }
 
-       if (assoc) {
-               rcu_read_lock();
-               have_sta = sta_info_get(sdata, ap_mld_addr);
-               rcu_read_unlock();
-       }
-
        if (!have_sta) {
                if (mlo)
                        new_sta = sta_info_alloc_with_link(sdata, ap_mld_addr,