1: 94720938363e ! 1: 865bf9690550 wifi: ath12k: validate RX frame length before undecapsulation @@ Metadata ## Commit message ## wifi: ath12k: validate RX frame length before undecapsulation  - Reject truncated raw frames before removing the FCS trailer. Without this - check, subtracting FCS_LEN from a shorter skb underflows and leaves the - FCS untrimmed. + Reject raw frames that are not longer than the FCS trailer before removing + it. For an skb shorter than FCS_LEN the unsigned length subtraction wraps, + so the skb_trim() length check turns the trim into a no-op and the FCS is + left in the frame.  - Also verify that the frame contains enough data for the 802.11 header and - the crypto header before moving the header to make room for the crypto - parameters. + Also verify that the frame is long enough for the crypto header and the + MIC, ICV and MMIC trailers before using the corresponding lengths, and + that the 802.11 header fits in the frame before moving it. + + In the TKIP MIC verification path, reject frames too short to hold the + RX descriptor, the 802.11 header, the TKIP IV and the MIC, ICV and FCS + trailers before computing the MIC input length, avoiding an unsigned + underflow before michael_mic().  Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3  @@ drivers/net/wireless/ath/ath12k/dp_rx.c: static void ath12k_dp_rx_h_undecap_raw(  + return 0; }  -+ if (msdu->len < FCS_LEN) ++ if (msdu->len <= FCS_LEN)  + return -EINVAL;  + skb_trim(msdu, msdu->len - FCS_LEN); @@ drivers/net/wireless/ath/ath12k/dp_rx.c: static void ath12k_dp_rx_h_undecap_raw(  hdr = (void *)msdu->data;  -@@ drivers/net/wireless/ath/ath12k/dp_rx.c: static void ath12k_dp_rx_h_undecap_raw(struct ath12k_pdev_dp *dp_pdev, + /* Tail */ + if (status->flag & RX_FLAG_IV_STRIPPED) { +- skb_trim(msdu, msdu->len - +- ath12k_dp_rx_crypto_mic_len(dp, enctype)); ++ int icv_len = ath12k_dp_rx_crypto_icv_len(dp_pdev, enctype); ++ int mic_len = ath12k_dp_rx_crypto_mic_len(dp, enctype); +  +- skb_trim(msdu, msdu->len - +- ath12k_dp_rx_crypto_icv_len(dp_pdev, enctype)); ++ if (msdu->len < mic_len + icv_len) ++ return -EINVAL; ++ ++ skb_trim(msdu, msdu->len - (mic_len + icv_len)); + } else { + /* MIC */ +- if (status->flag & RX_FLAG_MIC_STRIPPED) +- skb_trim(msdu, msdu->len - +- ath12k_dp_rx_crypto_mic_len(dp, enctype)); ++ if (status->flag & RX_FLAG_MIC_STRIPPED) { ++ int mic_len = ath12k_dp_rx_crypto_mic_len(dp, enctype); ++ ++ if (msdu->len < mic_len) ++ return -EINVAL; ++ ++ skb_trim(msdu, msdu->len - mic_len); ++ } +  + /* ICV */ +- if (status->flag & RX_FLAG_ICV_STRIPPED) +- skb_trim(msdu, msdu->len - +- ath12k_dp_rx_crypto_icv_len(dp_pdev, enctype)); ++ if (status->flag & RX_FLAG_ICV_STRIPPED) { ++ int icv_len; ++ ++ icv_len = ath12k_dp_rx_crypto_icv_len(dp_pdev, ++ enctype); ++ if (msdu->len < icv_len) ++ return -EINVAL; ++ ++ skb_trim(msdu, msdu->len - icv_len); ++ } + } +  + /* MMIC */ + if ((status->flag & RX_FLAG_MMIC_STRIPPED) && + !ieee80211_has_morefrags(hdr->frame_control) && +- enctype == HAL_ENCRYPT_TYPE_TKIP_MIC) ++ enctype == HAL_ENCRYPT_TYPE_TKIP_MIC) { ++ if (msdu->len < IEEE80211_CCMP_MIC_LEN) ++ return -EINVAL; ++ + skb_trim(msdu, msdu->len - IEEE80211_CCMP_MIC_LEN); ++ } +  + /* Head */ + if (status->flag & RX_FLAG_IV_STRIPPED) { hdr_len = ieee80211_hdrlen(hdr->frame_control); crypto_len = ath12k_dp_rx_crypto_param_len(dp_pdev, enctype);  @@ drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c: static int ath12k_wifi7_dp_rx_h_m if (!is_decrypted || rx_info->is_mcbc) return 0;  @@ drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c: static int ath12k_wifi7_dp_rx_h_verify_tkip_mic(struct ath12k_pdev_dp *dp_pdev, +  + key_conf = peer->keys[key_idx]; +  ++ if (msdu->len < head_len + tail_len) { ++ dev_kfree_skb_any(msdu); ++ return -EINVAL; ++ } ++ + data = msdu->data + head_len; + data_len = msdu->len - head_len - tail_len; + key = &key_conf->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY]; +@@ drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c: static int ath12k_wifi7_dp_rx_h_verify_tkip_mic(struct ath12k_pdev_dp *dp_pdev, }  ath12k_dp_rx_h_ppdu(dp_pdev, rx_info); 2: f8f445fbce4a < -: ------------ wifi: ath12k: rely on pskb_trim() to trim the received skb -: ------------ > 2: b984398e3874 wifi: ath12k: use MICHAEL_MIC_LEN for the TKIP Michael MIC -: ------------ > 3: a7cae05da6f0 wifi: ath12k: rely on pskb_trim() to trim the received skb 3: 83483da62941 ! 4: 9cb05e4e08b1 wifi: ath12k: use ieee80211_rx_list() to deliver packets to mac80211 @@ Commit message  Rework the receive path to collect processed frames on a list and deliver them to mac80211 as a batch with ieee80211_rx_list(), feeding - the result to napi_gro_receive() at the end of the NAPI poll. Delivering - frames in batches improves the icache footprint and lets GRO process - more frames together. + the result to napi_gro_receive() once the received packets have been + processed. Delivering frames in batches improves the icache footprint + and lets GRO process more frames together.  While at it, drop the linearization for multi-buffer MSDUs: chain the continuation buffers on the head skb with frag_list and deliver a single @@ drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c: static int ath12k_wifi7_dp_rx_pro  + /* When an MSDU spread over multiple buffers MSDU_END  + * tlvs are valid only in the last buffer. Copy those tlvs.  + */ -+ ath12k_dp_rx_desc_end_tlv_copy(hal, rxcb->rx_desc, lrx_desc); ++ if (rxcb->is_continuation) ++ ath12k_dp_rx_desc_end_tlv_copy(hal, rxcb->rx_desc, lrx_desc);  if (rxcb->is_frag) {  - skb_pull(msdu, hal_rx_desc_sz); @@ drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c: static int ath12k_wifi7_dp_rx_pro  + struct ieee80211_sta *sta = peer->sta;  +  + if (sta && sta->valid_links) { -+ int link_id; ++ int link_id = peer->link_id_map[rxcb->drv_link_id];   - rx_info->rx_status->flag |= RX_FLAG_SKIP_MONITOR | RX_FLAG_DUP_VALIDATED; -+ link_id = ath12k_hw_get_rx_link_id(dp->hw_params, -+ peer, rxcb, status); -+ if (link_id >= 0 && link_id < ARRAY_SIZE(sta->link)) -+ link_sta = rcu_dereference(sta->link[link_id]); ++ link_sta = rcu_dereference(sta->link[link_id]);  + } else if (sta) {  + link_sta = &sta->deflink;  + } @@ drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c: ath12k_wifi7_dp_rx_process_receiv  @@ drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c: ath12k_wifi7_dp_rx_process_received_packets(struct ath12k_dp *dp, struct hal_rx_desc_data rx_info; struct ath12k_dp *partner_dp; - u8 hw_link_id, pdev_idx; + u8 drv_link_id, pdev_idx, device_id;  + LIST_HEAD(list); int ret;