Skip to content

Commit 4330a0e

Browse files
committed
wifi: mt76: mt7996: fix out-of-bounds link array access in mt7996_tx()
When mac80211 leaves the link unspecified, mt7996_tx() substitutes the primary link id of the station or vif. That value is IEEE80211_LINK_UNSPECIFIED (0xf) until the first link has been added, and it is then used unchecked to index vif->link_conf[], mvif->mt76.link[] and sta->link[], all of which hold IEEE80211_MLD_MAX_NUM_LINKS (15) entries. Clamp the primary link id to the default link before using it, and use the clamped value for the link_sta fallback as well. Fixes: 1609b01 ("wifi: mt76: mt7996: Overwrite unspecified link_id in mt7996_tx()") Link: https://patch.msgid.link/20260801145334.1166751-10-nbd@nbd.name Signed-off-by: Felix Fietkau <nbd@nbd.name>
1 parent 9ba744a commit 4330a0e

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

  • drivers/net/wireless/mediatek/mt76/mt7996

drivers/net/wireless/mediatek/mt76/mt7996/main.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,20 +1515,26 @@ static void mt7996_tx(struct ieee80211_hw *hw,
15151515
struct ieee80211_vif *vif = info->control.vif;
15161516
struct mt7996_vif *mvif = vif ? (void *)vif->drv_priv : NULL;
15171517
struct mt76_wcid *wcid = &dev->mt76.global_wcid;
1518+
u8 deflink_id = IEEE80211_LINK_UNSPECIFIED;
15181519
u8 link_id = u32_get_bits(info->control.flags,
15191520
IEEE80211_TX_CTRL_MLO_LINK);
15201521

15211522
rcu_read_lock();
15221523

1524+
if (msta)
1525+
deflink_id = msta->deflink_id;
1526+
else if (mvif)
1527+
deflink_id = mvif->mt76.deflink_id;
1528+
1529+
/* the primary link is unset until the first link has been added */
1530+
if (deflink_id >= IEEE80211_MLD_MAX_NUM_LINKS)
1531+
deflink_id = 0;
1532+
15231533
/* Use primary link_id if the value from mac80211 is set to
15241534
* IEEE80211_LINK_UNSPECIFIED.
15251535
*/
1526-
if (link_id == IEEE80211_LINK_UNSPECIFIED) {
1527-
if (msta)
1528-
link_id = msta->deflink_id;
1529-
else if (mvif)
1530-
link_id = mvif->mt76.deflink_id;
1531-
}
1536+
if (link_id == IEEE80211_LINK_UNSPECIFIED)
1537+
link_id = deflink_id;
15321538

15331539
if (vif && ieee80211_vif_is_mld(vif)) {
15341540
struct ieee80211_bss_conf *link_conf;
@@ -1538,7 +1544,7 @@ static void mt7996_tx(struct ieee80211_hw *hw,
15381544

15391545
link_sta = rcu_dereference(sta->link[link_id]);
15401546
if (!link_sta)
1541-
link_sta = rcu_dereference(sta->link[msta->deflink_id]);
1547+
link_sta = rcu_dereference(sta->link[deflink_id]);
15421548

15431549
if (link_sta) {
15441550
memcpy(hdr->addr1, link_sta->addr, ETH_ALEN);

0 commit comments

Comments
 (0)