Skip to contentSkip to conversation

wifi: mac80211: reload TDLS header pointer after skb_linearize()

PATCH New Weigang He 1 participant 1 message Oct 21 mac80211

lore
Share & tools
lore

Weigang He

author
#0 lore raw

PATCH 1/1 wifi: mac80211: reload TDLS header pointer after skb_linearize()

ieee80211_process_tdls_channel_switch() sets tf = skb->data before it calls skb_linearize(), and reads tf->action_code afterwards.

ieee80211_rx_h_data() queues TDLS channel switch requests and responses to the interface after pulling only offsetof(struct ieee80211_tdls_data, u) bytes, so the skb can still be non-linear when the interface work handles it. Drivers that build paged RX skbs do this for every frame that does not fit into the skb head, e.g. iwlwifi (mvm), which is also the only mac80211 driver that sets NL80211_FEATURE_TDLS_CHANNEL_SWITCH. If the remaining data does not fit into the tailroom, skb_linearize() moves the data to a new head and frees the old one, and the action code is then read from freed memory. Depending on what that memory holds by then, the frame is handled as before or ends in the WARN_ON_ONCE() of the default case.

The frame only has to be a data frame with the TDLS ethertype from an authorized peer, e.g. relayed by the AP from another station in the BSS; the read happens before the sender is checked to be a TDLS peer.

Load tf after skb_linearize(), as the request and response handlers already do.

Found by static analysis tool CodeQL.

Fixes 8a4d32f30d11 ("mac80211: add TDLS channel-switch Rx flow")
Assisted-by LLM codeql

---

Notes:
Compile-tested only (ARCH=x86_64 and ARCH=arm64 allmodconfig, W=1). Not tested on hardware, and there is no reproducer. The frame can come from any station of the BSS via the AP; it needs an iwlwifi (mvm) device, the only mac80211 driver that sets NL80211_FEATURE_TDLS_CHANNEL_SWITCH.

The CodeQL query behind this report was written with LLM assistance, and the fix and changelog were drafted with LLM assistance; I have reviewed them.

 net/mac80211/tdls.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/mac80211/tdls.c +2 -1
index f663d28d9209c..71db07aa301b7 100644
@@ -2021,7 +2021,7 @@ void
 ieee80211_process_tdls_channel_switch(struct ieee80211_sub_if_data *sdata,
 				      struct sk_buff *skb)
 {
-	struct ieee80211_tdls_data *tf = (void *)skb->data;
+	struct ieee80211_tdls_data *tf;
 	struct wiphy *wiphy = sdata->local->hw.wiphy;
 
 	lockdep_assert_wiphy(wiphy);
@@ -2037,6 +2037,7 @@ ieee80211_process_tdls_channel_switch(struct ieee80211_sub_if_data *sdata,
 	 * The packet/size was already validated by mac80211 Rx path, only look
 	 * at the action type.
 	 */
+	tf = (void *)skb->data;
 	switch (tf->action_code) {
 	case WLAN_TDLS_CHANNEL_SWITCH_REQUEST:
 		ieee80211_process_tdls_channel_switch_req(sdata, skb);

base-commit: 71a77ab76e74131a101f4d2d2afb0dcbf81b4e3c

Signature · 1 line
2.43.0