wifi: mac80211: encap offload fixes
Subsystems (2)
Johannes Berg
maintainercover wifi: mac80211: encap offload fixes
Targeting wireless-next mostly because apparently nobody cares and it's really late in the cycle (and there's some risk involved).
johannes
Johannes Berg
maintainerPATCH 1/4 wifi: mac80211: fix unauthorised port check for encap offload
From: Johannes Berg <[email protected]>
The check in ieee80211_tx_dequeue() reads frame_control, addr1 and addr2 out of the skb, but for encapsulation offload that's just a random part of the ethernet addresses, so dropping depends on bits in the destination address. This is obviously wrong.
Refactor the check and short-circuit for ethernet format frames, it only needs the port-control flag check since those are locally generated and not forwarded frames.
--- net/mac80211/tx.c | 48 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-)
net/mac80211/tx.c +34 -14
@@ -3882,6 +3882,38 @@ static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,return true; } +static bool ieee80211_drop_unauth_port (struct ieee80211_tx_data *tx) +{ +struct ieee80211_tx_info *info =IEEE80211_SKB_CB (tx->skb); +struct ieee80211_hdr *hdr; + +if (likely (test_sta_flag (tx->sta,WLAN_STA_AUTHORIZED ))) +return false; + +if (info->flags &IEEE80211_TX_CTL_INJECTED ) +return false; + +if (ieee80211_vif_is_mesh (&tx->sdata->vif) || + tx->sdata->vif.type ==NL80211_IFTYPE_OCB ) +return false; + +/* no need to check forwarding here */ +if (info->flags &IEEE80211_TX_CTL_HW_80211_ENCAP ) +return !(info->control.flags &IEEE80211_TX_CTRL_PORT_CTRL_PROTO ); + + hdr = (struct ieee80211_hdr *)tx->skb->data; + +if (!ieee80211_is_data_present (hdr->frame_control) || +is_multicast_ether_addr (hdr->addr1)) +return false; + +if ((info->control.flags &IEEE80211_TX_CTRL_PORT_CTRL_PROTO ) && +ieee80211_is_our_addr (tx->sdata, hdr->addr2,NULL )) +return false; + +return true; +} +struct sk_buff *ieee80211_tx_dequeue (struct ieee80211_hw *hw,struct ieee80211_txq *txq) {
@@ -3948,20 +3980,8 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,if (txq->sta) { tx.sta = container_of(txq->sta, struct sta_info, sta); -/* -* Drop unicast frames to unauthorised stations unless they are -* injected frames or EAPOL frames from the local station. -*/ -if (unlikely (!(info->flags &IEEE80211_TX_CTL_INJECTED ) && -ieee80211_is_data_present (hdr->frame_control) && - !ieee80211_vif_is_mesh (&tx.sdata->vif) && - tx.sdata->vif.type !=NL80211_IFTYPE_OCB && - !is_multicast_ether_addr (hdr->addr1) && - !test_sta_flag (tx.sta,WLAN_STA_AUTHORIZED ) && - (!(info->control.flags & -IEEE80211_TX_CTRL_PORT_CTRL_PROTO ) || - !ieee80211_is_our_addr (tx.sdata, hdr->addr2, -NULL )))) { + +if (unlikely (ieee80211_drop_unauth_port (&tx))) {I802_DEBUG_INC (local->tx_handlers_drop_unauth_port);ieee80211_free_txskb (&local->hw, skb); goto begin;
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH 2/4 wifi: mac80211: fix key selection for encap offload frames
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
ieee80211_tx_h_select_key() assumes the frame is in 802.11 format for picking the key, at least when there's no pairwise TK for the STA to transmit with.
For unicast this is likely not relevant because if there's no pairwise TK for the STA there's probably not going to be any other key either. But multicast encapsulation offload frames have no STA, so it looks at the ethernet header as if it was 802.11. This may not matter very much since multicast encapsulation offload is likely to ignore the key selection, but it's still wrong.
Create a separate selection function that doesn't (need to) look at the frame header - it's data anyway, so either unicast to a station (with sta pointer) or multicast. For MLO, the driver has to duplicate the frame and select the key anyway, so just skip it in that case entirely.
--- net/mac80211/tx.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-)
net/mac80211/tx.c +31 -6
@@ -592,6 +592,34 @@ ieee80211_select_link_key(struct ieee80211_tx_data *tx)return NULL ; } +/* +* An 802.3 frame is always a data frame, so there are no 802.11 addresses to +* look at: with a station the pairwise key is all that can apply, without one +* the frame is group addressed. On an MLD the driver has to pick the group key +* itself, as the same frame goes out on several links that each have their own. +*/ +static ieee80211_tx_result +ieee80211_select_key_8023 (struct ieee80211_tx_data *tx) +{ +struct ieee80211_tx_info *info =IEEE80211_SKB_CB (tx->skb); + +if (unlikely (info->flags &IEEE80211_TX_INTFL_DONT_ENCRYPT )) +return TX_CONTINUE ; + +if (tx->sta) { + tx->key =rcu_dereference (tx->sta->ptk[tx->sta->ptk_idx]); +if (!tx->key) + tx->key =rcu_dereference (tx->sdata->default_unicast_key); + }else if (!ieee80211_vif_is_mld (&tx->sdata->vif)) { + tx->key =rcu_dereference (tx->sdata->deflink.default_multicast_key); + } + +if (tx->key && tx->key->flags &KEY_FLAG_UPLOADED_TO_HARDWARE ) + info->control.hw_key = &tx->key->conf; + +return TX_CONTINUE ; +} + static ieee80211_tx_result debug_noinlineieee80211_tx_h_select_key (struct ieee80211_tx_data *tx) {
@@ -599,6 +627,9 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)struct ieee80211_tx_info *info =IEEE80211_SKB_CB (tx->skb);struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; +if (info->control.flags &IEEE80211_TX_CTL_HW_80211_ENCAP ) +return ieee80211_select_key_8023 (tx); +if (unlikely (info->flags &IEEE80211_TX_INTFL_DONT_ENCRYPT )) { tx->key =NULL ;return TX_CONTINUE ;
@@ -615,12 +646,6 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)else tx->key =NULL ; -if (info->flags &IEEE80211_TX_CTL_HW_80211_ENCAP ) { -if (tx->key && tx->key->flags &KEY_FLAG_UPLOADED_TO_HARDWARE ) - info->control.hw_key = &tx->key->conf; -return TX_CONTINUE ; - } -if (tx->key) {bool skip_hw = false;
Signature · 1 line
2.55.0
PATCH 1/1 mac80211: tx: Use info->flags in ieee80211_tx_h_select_key()
Without this ieee80211_select_key_8023() is never called and wifi never connects.
--- net/mac80211/tx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/mac80211/tx.c +1 -1
@@ -648,7 +648,7 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)struct ieee80211_tx_info *info =IEEE80211_SKB_CB (tx->skb);struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; -if (info->control.flags &IEEE80211_TX_CTL_HW_80211_ENCAP ) +if (info->flags &IEEE80211_TX_CTL_HW_80211_ENCAP )return ieee80211_select_key_8023 (tx);if (unlikely (info->flags &IEEE80211_TX_INTFL_DONT_ENCRYPT )) {
Signature · 28 lines
2.55.0 I noticed that in next-20260907 my wifi adapter fails to connect to the wireless network. As this still worked in v7.3-rc2 I bisected the issue and found the offending commit to be this merge: commit d1352d1b277913736903eff185191c4f9723e0de Merge: 7e615d9c216c 1b60ed34f712 Author: Mark Brown <[email protected]> Date: Mon Sep 7 13:26:24 2026 +0100 Merge branch 'for-next' of https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git So I examined the patch created by git diff 7e615d9c216c d1352d1b2779 by applying it piece by piece to commit 7e615d9c216c. The result of this procedure was the patch above as a minimal fix in next-20260907. The wirless hardware used is this: 09:00.0 Network controller [0280]: MEDIATEK Corp. MT7925 802.11be 160MHz 2x2 PCIe Wireless Network Adapter [Filogic 360] [14c3:7925] Using printk()s in ieee80211_select_key_8023() (in next-20260907) I noticed that ieee80211_select_key_8023() is never called when using the info->control.flags test. Bert Karwatzki
Johannes Berg
maintainerPATCH 3/4 wifi: mac80211: don't send encap offload frames unencrypted
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
For 802.11 frames, ieee80211_tx_h_select_key() drops a data frame that ended up without a key if the station requires encryption, so that traffic can never leak out unprotected. Encapsulation offload erroneously didn't get this code path. Fix that.
--- net/mac80211/tx.c | 3 +++ 1 file changed, 3 insertions(+)
net/mac80211/tx.c +3 -0
@@ -610,6 +610,9 @@ ieee80211_select_key_8023(struct ieee80211_tx_data *tx) tx->key =rcu_dereference (tx->sta->ptk[tx->sta->ptk_idx]);if (!tx->key) tx->key =rcu_dereference (tx->sdata->default_unicast_key); + +if (!tx->key &&test_sta_flag (tx->sta,WLAN_STA_USES_ENCRYPTION )) +return TX_DROP ; }else if (!ieee80211_vif_is_mld (&tx->sdata->vif)) { tx->key =rcu_dereference (tx->sdata->deflink.default_multicast_key); }
Signature · 1 line
2.55.0
Johannes Berg
maintainerPATCH 4/4 wifi: mac80211: drop encap offload frames with a tainted key
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
When a key is tainted, which happens in some WoWLAN and extended key ID scenarios, frames that would use it should be dropped. Fix that for encapsulation offload frames.
--- net/mac80211/tx.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
net/mac80211/tx.c +7 -1
@@ -617,7 +617,13 @@ ieee80211_select_key_8023(struct ieee80211_tx_data *tx) tx->key =rcu_dereference (tx->sdata->deflink.default_multicast_key); } -if (tx->key && tx->key->flags &KEY_FLAG_UPLOADED_TO_HARDWARE ) +if (!tx->key) +return TX_CONTINUE ; + +if (unlikely (tx->key->flags &KEY_FLAG_TAINTED )) +return TX_DROP ; + +if (tx->key->flags &KEY_FLAG_UPLOADED_TO_HARDWARE ) info->control.hw_key = &tx->key->conf;return TX_CONTINUE ;
Signature · 1 line
2.55.0