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 From: Benjamin Berg Resolve the APs station in case a beacon is received for a non-transmitted BSS. This is important because the station has the key information for beacon protection. Without this change, mac80211 will not verify the beacon when connected to a non-transmitted BSSID. Most hardware is not affected as the frames are already verified. But for example the virtual hwsim driver is. Signed-off-by: Benjamin Berg Reviewed-by: Johannes Berg --- net/mac80211/rx.c | 65 +++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index 2568b0b95be6..5f09a8766269 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -5332,6 +5332,29 @@ static bool ieee80211_rx_valid_freq(int freq, struct ieee80211_link_data *link) return freq == conf->def.chan->center_freq; } +static struct ieee80211_link_data * +ieee80211_link_from_freq(struct ieee80211_sub_if_data *sdata, int freq) +{ + struct ieee80211_link_data *link; + + if (ieee80211_vif_is_mld(&sdata->vif)) { + struct ieee80211_chanctx_conf *conf; + + for_each_link_data_rcu(sdata, link) { + conf = rcu_dereference(link->conf->chanctx_conf); + if (!conf || !conf->def.chan) + continue; + + if (freq == conf->def.chan->center_freq) + return link; + } + + return &sdata->deflink; + } + + return &sdata->deflink; +} + /* * This is the actual Rx frames handler. as it belongs to Rx path it must * be called with rcu_read_lock protection. @@ -5492,6 +5515,7 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, list_for_each_entry_rcu(sdata, &local->interfaces, list) { struct ieee80211_link_data *link = NULL; + const u8 *addr = hdr->addr2; if (!ieee80211_sdata_running(sdata)) continue; @@ -5503,16 +5527,32 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, link_sta = NULL; link = NULL; + /* + * Switch to do the STA lookup using the non-transmitted BSSID + * for beacon frames from the transmitted BSSID. This ensures + * that the keys for beacon protection are available during + * later processing. + */ + if (ieee80211_is_beacon(fc) && + sdata->vif.type == NL80211_IFTYPE_STATION) { + link = ieee80211_link_from_freq(sdata, status->freq); + + if (link->conf->nontransmitted && + ether_addr_equal(addr, + link->conf->transmitter_bssid)) + addr = link->conf->bssid; + } + /* Try to resolve the station */ if (!ieee80211_vif_is_mld(&sdata->vif)) { - sta = sta_info_get_bss(sdata, hdr->addr2); + sta = sta_info_get_bss(sdata, addr); if (sta) { link_sta = &sta->deflink; link = &sdata->deflink; } } else { - link_sta = link_sta_info_get_bss(sdata, hdr->addr2); + link_sta = link_sta_info_get_bss(sdata, addr); if (link_sta) link = rcu_dereference(sdata->link[link_sta->link_id]); @@ -5539,26 +5579,7 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, } /* No station, try to resolve the link and RX */ - if (ieee80211_vif_is_mld(&sdata->vif)) { - struct ieee80211_chanctx_conf *conf; - bool found = false; - - for_each_link_data_rcu(sdata, link) { - conf = rcu_dereference(link->conf->chanctx_conf); - if (!conf || !conf->def.chan) - continue; - - if (status->freq == conf->def.chan->center_freq) { - found = true; - break; - } - } - - if (!found) - link = &sdata->deflink; - } else { - link = &sdata->deflink; - } + link = ieee80211_link_from_freq(sdata, status->freq); if (rx_data_pending) { ieee80211_prepare_and_rx_handle(&rx, skb, false); -- 2.56.0