From: Benjamin Berg Set the link_id in the SKB status to the invalid value of 0xf when the link ID is not valid. Also update the test in ieee80211_rx_handlers to correctly check this case. This avoids switching to an invalid link during RX of a single frame (when updating the link is not needed). It also means that the SKB link_id now has a more reasonable value as it is possible to differentiate the non-valid case from the case where the value is set to 0. Add back the appropriate checks before trying to use the link_id for access to arrays. These were removed in commit 4db13371e217 ("wifi: mac80211: refactor RX link_id and station handling"). Finally, this also fixes the link_sta lookup to use the correct link ID, rather than an old value from rx->link_id. Fixes: 2d03b83ef762 ("wifi: mac80211: fix non-MLD link ID handling") Fixes: 4db13371e217 ("wifi: mac80211: refactor RX link_id and station handling") Signed-off-by: Benjamin Berg Reviewed-by: Johannes Berg --- include/net/mac80211.h | 3 ++- net/mac80211/ap.c | 3 ++- net/mac80211/iface.c | 7 +++++-- net/mac80211/mlme.c | 10 ++++++---- net/mac80211/rx.c | 28 ++++++++++++++++++++-------- net/mac80211/scan.c | 5 +++-- 6 files changed, 38 insertions(+), 18 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index 76ff86ff9974..5962d1416bfe 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -1772,7 +1772,8 @@ enum mac80211_rx_encoding { * @zero_length_psdu_type: radiotap type of the 0-length PSDU * @link_id: id of the link used to receive the packet. Set and used by * mac80211 internally, it uses @freq set by the driver to identify the - * correct link per vif. + * correct link per vif. Set to %IEEE80211_LINK_UNSPECIFIED for non-MLD + * or if link information is not applicable. */ struct ieee80211_rx_status { u64 mactime; diff --git a/net/mac80211/ap.c b/net/mac80211/ap.c index 9a3122da84bc..eaad7b70b887 100644 --- a/net/mac80211/ap.c +++ b/net/mac80211/ap.c @@ -66,7 +66,8 @@ ieee80211_rx_eml_op_mode_notif(struct ieee80211_sub_if_data *sdata, struct sta_info *sta; int opt_len = 0; - if (!ieee80211_vif_is_mld(&sdata->vif)) + if (!ieee80211_vif_is_mld(&sdata->vif) || + status->link_id == IEEE80211_LINK_UNSPECIFIED) return; /* eMLSR and eMLMR can't be enabled at the same time */ diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c index d0b0a503b229..63a371c79183 100644 --- a/net/mac80211/iface.c +++ b/net/mac80211/iface.c @@ -1712,8 +1712,11 @@ static void ieee80211_iface_process_skb(struct ieee80211_local *local, break; status = IEEE80211_SKB_RXCB(skb); - link_sta = wiphy_dereference(local->hw.wiphy, - sta->link[status->link_id]); + if (status->link_id == IEEE80211_LINK_UNSPECIFIED) + link_sta = &sta->deflink; + else + link_sta = wiphy_dereference(local->hw.wiphy, + sta->link[status->link_id]); if (link_sta) ieee80211_ht_handle_chanwidth_notif(local, sdata, sta, link_sta, chanwidth, diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c index 15d7482a4a22..bcd942bae8f1 100644 --- a/net/mac80211/mlme.c +++ b/net/mac80211/mlme.c @@ -11974,10 +11974,12 @@ void ieee80211_sta_rx_queued_frame(struct ieee80211_sub_if_data *sdata, rx_status = (struct ieee80211_rx_status *) skb->cb; fc = le16_to_cpu(mgmt->frame_control); - link = sdata_dereference(sdata->link[rx_status->link_id], - sdata); - if (!link) - return; + if (rx_status->link_id != IEEE80211_LINK_UNSPECIFIED) { + link = sdata_dereference(sdata->link[rx_status->link_id], + sdata); + if (!link) + return; + } switch (fc & IEEE80211_FCTL_STYPE) { case IEEE80211_STYPE_BEACON: diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index 905fd70491ce..2568b0b95be6 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -4203,6 +4203,7 @@ static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx, while ((skb = __skb_dequeue(frames))) { struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb); + int link_id; /* * Most fields are valid across frames. However, @@ -4211,18 +4212,27 @@ static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx, * and link_sta accordingly. */ rx->skb = skb; + link_id = status->link_id == IEEE80211_LINK_UNSPECIFIED ? -1 : status->link_id; if (ieee80211_vif_is_mld(&rx->sdata->vif) && - unlikely(rx->link_id != status->link_id)) { + unlikely(rx->link_id != link_id)) { + rx->link_id = link_id; + + if (link_id >= 0) + rx->link = rcu_dereference(rx->sdata->link[link_id]); + else + rx->link = &rx->sdata->deflink; + if (rx->sta) { - rx->link_sta = - rcu_dereference(rx->sta->link[rx->link_id]); + if (WARN_ON_ONCE(link_id < 0)) + rx->link_sta = NULL; + else + rx->link_sta = + rcu_dereference(rx->sta->link[link_id]); - /* Link got disabled, just use deflink */ + /* Link disabled or invalid, just use deflink */ if (!rx->link_sta) rx->link_sta = &rx->sta->deflink; } - rx->link_id = status->link_id; - rx->link = rcu_dereference(rx->sdata->link[status->link_id]); } if (WARN_ON_ONCE(!rx->link)) { @@ -5156,7 +5166,8 @@ static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx, } status = IEEE80211_SKB_RXCB(skb); - status->link_id = rx->link_id < 0 ? 0 : rx->link_id; + status->link_id = + rx->link_id < 0 ? IEEE80211_LINK_UNSPECIFIED : rx->link_id; ieee80211_rx_8023(rx, fast_rx, orig_len); @@ -5227,7 +5238,8 @@ static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx, } status = IEEE80211_SKB_RXCB(rx->skb); - status->link_id = rx->link_id < 0 ? 0 : rx->link_id; + status->link_id = + rx->link_id < 0 ? IEEE80211_LINK_UNSPECIFIED : rx->link_id; if (ieee80211_is_s1g_beacon(hdr->frame_control)) { ieee80211_invoke_rx_handlers(rx); diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c index 8a66d2e020f9..69eb991d9b5a 100644 --- a/net/mac80211/scan.c +++ b/net/mac80211/scan.c @@ -214,8 +214,9 @@ ieee80211_bss_info_update(struct ieee80211_local *local, if (ieee80211_vif_is_mld(&scan_sdata->vif)) { s8 link_id = rx_status->link_id; - link_conf = - rcu_dereference(scan_sdata->vif.link_conf[link_id]); + if (link_id != IEEE80211_LINK_UNSPECIFIED) + link_conf = + rcu_dereference(scan_sdata->vif.link_conf[link_id]); } else { link_conf = &scan_sdata->vif.bss_conf; } -- 2.56.0