ath11k_dp_rx_h_csum_offload() marks every received MSDU CHECKSUM_UNNECESSARY unless the attention TLV reports an IP or TCP/UDP checksum failure. Those bits report a checksum the hardware computed and found wrong, so both are also clear for a frame whose transport checksum it never computed: any protocol other than TCP and UDP, such as ICMP, ICMPv6 or GRE, and a TCP or UDP frame whose headers it did not parse within the first 256 bytes. An IP fragment carries only part of the datagram its checksum covers. The descriptor also describes only the MSDU the hardware received. A frame that ath11k_dp_rx_h_defrag() reassembles from 802.11 fragments keeps the descriptor of its first fragment, of which only the MSDU length is rewritten, so the flags say nothing about the payload of the later fragments. With raw decap (frame_mode=0 or crypto_mode=1) an A-MSDU reaches mac80211 as one MPDU; when it spans several RX buffers and ath11k_dp_rx_msdu_coalesce() moves it into a larger buffer, ieee80211_amsdu_to_8023s() hands that skb, ip_summed included, to the last subframe. The stack then skips the checks it would make: icmp_rcv() takes the checksum as verified, and reassembly keeps CHECKSUM_UNNECESSARY when every fragment carries it, so a UDP datagram that arrives in IP fragments is never checked. By the code this holds for every ath11k chip and frame mode and for any frame an associated peer sends. The MSDU start TLV carries the flags that say what the hardware parsed: TCP, UDP, IP fragment, and whether the fixed IP header and the TCP/UDP header were parsed. Mark a frame CHECKSUM_UNNECESSARY only when it is TCP or UDP, not a fragment, and both headers were parsed, and never for a reassembled 802.11 frame or a raw A-MSDU; ath10k_htt_rx_get_csum_state() already leaves a frame that is neither TCP nor UDP to the stack. The flags sit in a different descriptor layout on each chip family, so add a hw_ops accessor for the MSDU start word that holds them. Found by an LLM review (Claude) of the code. Fixes: d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices") Signed-off-by: Julius Bairaktaris --- v2: also leave a frame reassembled from 802.11 fragments and a raw A-MSDU to the stack (Sashiko); discovery line reworded. drivers/net/wireless/ath/ath11k/dp_rx.c | 61 ++++++++++++++++++++++++- drivers/net/wireless/ath/ath11k/hw.c | 22 +++++++++ drivers/net/wireless/ath/ath11k/hw.h | 1 + 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c index 6d95f7b343a5..a2c359cc8e92 100644 --- a/drivers/net/wireless/ath/ath11k/dp_rx.c +++ b/drivers/net/wireless/ath/ath11k/dp_rx.c @@ -1860,18 +1860,75 @@ static struct sk_buff *ath11k_dp_rx_get_msdu_last_buf(struct sk_buff_head *msdu_ return NULL; } +static bool ath11k_dp_rx_h_is_raw_amsdu(struct ath11k_base *ab, + struct sk_buff *msdu) +{ + struct ath11k_skb_rxcb *rxcb = ATH11K_SKB_RXCB(msdu); + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)msdu->data; + + if (ath11k_dp_rx_h_msdu_start_decap_type(ab, rxcb->rx_desc) != + DP_RX_DECAP_TYPE_RAW) + return false; + + /* + * Neither an MPDU the hardware delivered as several MSDUs nor a frame + * too short to tell is taken as a single MSDU. + */ + if (!rxcb->is_first_msdu || !rxcb->is_last_msdu) + return true; + + if (msdu->len < sizeof(hdr->frame_control)) + return true; + + if (!ieee80211_is_data_qos(hdr->frame_control)) + return false; + + if (msdu->len < ieee80211_hdrlen(hdr->frame_control)) + return true; + + return *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_A_MSDU_PRESENT; +} + static void ath11k_dp_rx_h_csum_offload(struct ath11k *ar, struct sk_buff *msdu) { struct ath11k_skb_rxcb *rxcb = ATH11K_SKB_RXCB(msdu); struct rx_attention *rx_attention; bool ip_csum_fail, l4_csum_fail; + u32 info2; rx_attention = ath11k_dp_rx_get_attention(ar->ab, rxcb->rx_desc); ip_csum_fail = ath11k_dp_rx_h_attn_ip_cksum_fail(rx_attention); l4_csum_fail = ath11k_dp_rx_h_attn_l4_cksum_fail(rx_attention); + info2 = ar->ab->hw_params.hw_ops->rx_desc_get_msdu_start_info2(rxcb->rx_desc); + + msdu->ip_summed = CHECKSUM_NONE; + + /* + * The descriptor describes one MSDU as the hardware received it. A + * frame reassembled from 802.11 fragments keeps the descriptor of its + * first fragment, and mac80211 splits a raw A-MSDU into subframes the + * descriptor does not describe one by one. + */ + if (rxcb->is_frag || ath11k_dp_rx_h_is_raw_amsdu(ar->ab, msdu)) + return; + + if (ip_csum_fail || l4_csum_fail) + return; + + /* + * The failure bits only report a checksum the hardware computed, so + * they are also clear for a frame it did not check. It checks the + * TCP or UDP checksum of a frame whose IP and TCP/UDP headers it + * parsed; an IP fragment does not carry the whole datagram the + * checksum covers. + */ + if (!(info2 & (RX_MSDU_START_INFO2_TCP | RX_MSDU_START_INFO2_UDP)) || + (info2 & RX_MSDU_START_INFO2_IP_FRAG) || + !(info2 & RX_MSDU_START_INFO2_IP_FIXED_HDR_VALID) || + !(info2 & RX_MSDU_START_INFO2_IP_TCP_UDP_HDR_VALID)) + return; - msdu->ip_summed = (ip_csum_fail || l4_csum_fail) ? - CHECKSUM_NONE : CHECKSUM_UNNECESSARY; + msdu->ip_summed = CHECKSUM_UNNECESSARY; } int ath11k_dp_rx_crypto_mic_len(struct ath11k *ar, enum hal_encrypt_type enctype) diff --git a/drivers/net/wireless/ath/ath11k/hw.c b/drivers/net/wireless/ath/ath11k/hw.c index 93f9a03c48dc..096366b85849 100644 --- a/drivers/net/wireless/ath/ath11k/hw.c +++ b/drivers/net/wireless/ath/ath11k/hw.c @@ -272,6 +272,11 @@ static u8 ath11k_hw_ipq8074_rx_desc_get_decap_type(struct hal_rx_desc *desc) __le32_to_cpu(desc->u.ipq8074.msdu_start.info2)); } +static u32 ath11k_hw_ipq8074_rx_desc_get_msdu_start_info2(struct hal_rx_desc *desc) +{ + return __le32_to_cpu(desc->u.ipq8074.msdu_start.info2); +} + static u8 ath11k_hw_ipq8074_rx_desc_get_mesh_ctl(struct hal_rx_desc *desc) { return FIELD_GET(RX_MSDU_START_INFO2_MESH_CTRL_PRESENT, @@ -449,6 +454,11 @@ static u8 ath11k_hw_qcn9074_rx_desc_get_decap_type(struct hal_rx_desc *desc) __le32_to_cpu(desc->u.qcn9074.msdu_start.info2)); } +static u32 ath11k_hw_qcn9074_rx_desc_get_msdu_start_info2(struct hal_rx_desc *desc) +{ + return __le32_to_cpu(desc->u.qcn9074.msdu_start.info2); +} + static u8 ath11k_hw_qcn9074_rx_desc_get_mesh_ctl(struct hal_rx_desc *desc) { return FIELD_GET(RX_MSDU_START_INFO2_MESH_CTRL_PRESENT, @@ -626,6 +636,11 @@ static u8 ath11k_hw_wcn6855_rx_desc_get_decap_type(struct hal_rx_desc *desc) __le32_to_cpu(desc->u.wcn6855.msdu_start.info2)); } +static u32 ath11k_hw_wcn6855_rx_desc_get_msdu_start_info2(struct hal_rx_desc *desc) +{ + return __le32_to_cpu(desc->u.wcn6855.msdu_start.info2); +} + static u8 ath11k_hw_wcn6855_rx_desc_get_mesh_ctl(struct hal_rx_desc *desc) { return FIELD_GET(RX_MSDU_START_INFO2_MESH_CTRL_PRESENT, @@ -914,6 +929,7 @@ const struct ath11k_hw_ops ipq8074_ops = { .rx_desc_get_encrypt_type = ath11k_hw_ipq8074_rx_desc_get_encrypt_type, .rx_desc_get_decap_type = ath11k_hw_ipq8074_rx_desc_get_decap_type, .rx_desc_get_mesh_ctl = ath11k_hw_ipq8074_rx_desc_get_mesh_ctl, + .rx_desc_get_msdu_start_info2 = ath11k_hw_ipq8074_rx_desc_get_msdu_start_info2, .rx_desc_get_ldpc_support = ath11k_hw_ipq8074_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_ipq8074_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_ipq8074_rx_desc_get_mpdu_fc_valid, @@ -954,6 +970,7 @@ const struct ath11k_hw_ops ipq6018_ops = { .rx_desc_get_encrypt_type = ath11k_hw_ipq8074_rx_desc_get_encrypt_type, .rx_desc_get_decap_type = ath11k_hw_ipq8074_rx_desc_get_decap_type, .rx_desc_get_mesh_ctl = ath11k_hw_ipq8074_rx_desc_get_mesh_ctl, + .rx_desc_get_msdu_start_info2 = ath11k_hw_ipq8074_rx_desc_get_msdu_start_info2, .rx_desc_get_ldpc_support = ath11k_hw_ipq8074_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_ipq8074_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_ipq8074_rx_desc_get_mpdu_fc_valid, @@ -994,6 +1011,7 @@ const struct ath11k_hw_ops qca6390_ops = { .rx_desc_get_encrypt_type = ath11k_hw_ipq8074_rx_desc_get_encrypt_type, .rx_desc_get_decap_type = ath11k_hw_ipq8074_rx_desc_get_decap_type, .rx_desc_get_mesh_ctl = ath11k_hw_ipq8074_rx_desc_get_mesh_ctl, + .rx_desc_get_msdu_start_info2 = ath11k_hw_ipq8074_rx_desc_get_msdu_start_info2, .rx_desc_get_ldpc_support = ath11k_hw_ipq8074_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_ipq8074_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_ipq8074_rx_desc_get_mpdu_fc_valid, @@ -1034,6 +1052,7 @@ const struct ath11k_hw_ops qcn9074_ops = { .rx_desc_get_encrypt_type = ath11k_hw_qcn9074_rx_desc_get_encrypt_type, .rx_desc_get_decap_type = ath11k_hw_qcn9074_rx_desc_get_decap_type, .rx_desc_get_mesh_ctl = ath11k_hw_qcn9074_rx_desc_get_mesh_ctl, + .rx_desc_get_msdu_start_info2 = ath11k_hw_qcn9074_rx_desc_get_msdu_start_info2, .rx_desc_get_ldpc_support = ath11k_hw_qcn9074_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_qcn9074_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_qcn9074_rx_desc_get_mpdu_fc_valid, @@ -1074,6 +1093,7 @@ const struct ath11k_hw_ops wcn6855_ops = { .rx_desc_get_encrypt_type = ath11k_hw_wcn6855_rx_desc_get_encrypt_type, .rx_desc_get_decap_type = ath11k_hw_wcn6855_rx_desc_get_decap_type, .rx_desc_get_mesh_ctl = ath11k_hw_wcn6855_rx_desc_get_mesh_ctl, + .rx_desc_get_msdu_start_info2 = ath11k_hw_wcn6855_rx_desc_get_msdu_start_info2, .rx_desc_get_ldpc_support = ath11k_hw_wcn6855_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_wcn6855_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_wcn6855_rx_desc_get_mpdu_fc_valid, @@ -1114,6 +1134,7 @@ const struct ath11k_hw_ops wcn6750_ops = { .rx_desc_get_encrypt_type = ath11k_hw_qcn9074_rx_desc_get_encrypt_type, .rx_desc_get_decap_type = ath11k_hw_qcn9074_rx_desc_get_decap_type, .rx_desc_get_mesh_ctl = ath11k_hw_qcn9074_rx_desc_get_mesh_ctl, + .rx_desc_get_msdu_start_info2 = ath11k_hw_qcn9074_rx_desc_get_msdu_start_info2, .rx_desc_get_ldpc_support = ath11k_hw_qcn9074_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_qcn9074_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_qcn9074_rx_desc_get_mpdu_fc_valid, @@ -1155,6 +1176,7 @@ const struct ath11k_hw_ops ipq5018_ops = { .rx_desc_get_encrypt_type = ath11k_hw_qcn9074_rx_desc_get_encrypt_type, .rx_desc_get_decap_type = ath11k_hw_qcn9074_rx_desc_get_decap_type, .rx_desc_get_mesh_ctl = ath11k_hw_qcn9074_rx_desc_get_mesh_ctl, + .rx_desc_get_msdu_start_info2 = ath11k_hw_qcn9074_rx_desc_get_msdu_start_info2, .rx_desc_get_ldpc_support = ath11k_hw_qcn9074_rx_desc_get_ldpc_support, .rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_qcn9074_rx_desc_get_mpdu_seq_ctl_vld, .rx_desc_get_mpdu_fc_valid = ath11k_hw_qcn9074_rx_desc_get_mpdu_fc_valid, diff --git a/drivers/net/wireless/ath/ath11k/hw.h b/drivers/net/wireless/ath/ath11k/hw.h index 4996536fbd14..8725e119707b 100644 --- a/drivers/net/wireless/ath/ath11k/hw.h +++ b/drivers/net/wireless/ath/ath11k/hw.h @@ -249,6 +249,7 @@ struct ath11k_hw_ops { u32 (*rx_desc_get_encrypt_type)(struct hal_rx_desc *desc); u8 (*rx_desc_get_decap_type)(struct hal_rx_desc *desc); u8 (*rx_desc_get_mesh_ctl)(struct hal_rx_desc *desc); + u32 (*rx_desc_get_msdu_start_info2)(struct hal_rx_desc *desc); bool (*rx_desc_get_ldpc_support)(struct hal_rx_desc *desc); bool (*rx_desc_get_mpdu_seq_ctl_vld)(struct hal_rx_desc *desc); bool (*rx_desc_get_mpdu_fc_valid)(struct hal_rx_desc *desc); -- 2.53.0 ath12k_wifi7_dp_rx_h_csum_offload() marks every received MSDU CHECKSUM_UNNECESSARY unless the MSDU end TLV reports an IP or TCP/UDP checksum failure. Those bits report a checksum the hardware computed and found wrong, so both are also clear for a frame whose transport checksum it never computed: any protocol other than TCP and UDP, such as ICMP, ICMPv6 or GRE, a TCP or UDP frame whose headers it did not parse, and an IP fragment, which carries only part of the datagram its checksum covers. A frame that ath12k_wifi7_dp_rx_h_defrag() reassembles from 802.11 fragments keeps the descriptor of its first fragment, of which only the MSDU length is rewritten, so its flags say nothing about the payload of the later fragments. icmp_rcv() then takes the checksum as verified, and a UDP datagram whose IP fragments all carry CHECKSUM_UNNECESSARY keeps it after reassembly. ath11k has the same check. Extract the protocol, fragment and header-parsed flags of the MSDU end TLV with the other descriptor fields on each chip, from the last buffer of the MSDU like the other MSDU end fields, and mark a frame CHECKSUM_UNNECESSARY only when it is TCP or UDP, not a fragment, its IP and TCP/UDP headers were parsed, and it was not reassembled from 802.11 fragments. Unlike ath11k, ath12k needs no case for a raw A-MSDU: nothing in the driver sets ATH12K_FLAG_RAW_MODE. Found by an LLM review (Claude) of the code. Fixes: d889913205cf ("wifi: ath12k: driver for Qualcomm Wi-Fi 7 devices") Signed-off-by: Julius Bairaktaris --- v2: also leave a frame reassembled from 802.11 fragments to the stack (Sashiko, on 1/6); read l4_csum_checked from the last buffer, like the other MSDU end fields since commit 1e678e37ff13; discovery line reworded. drivers/net/wireless/ath/ath12k/hal.h | 1 + drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c | 11 ++++++++++- drivers/net/wireless/ath/ath12k/wifi7/hal_qcc2072.c | 11 +++++++++++ drivers/net/wireless/ath/ath12k/wifi7/hal_qcn9274.c | 12 ++++++++++++ drivers/net/wireless/ath/ath12k/wifi7/hal_wcn7850.c | 12 ++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath12k/hal.h b/drivers/net/wireless/ath/ath12k/hal.h index 343e1636b4cc..003baf0d3ea0 100644 --- a/drivers/net/wireless/ath/ath12k/hal.h +++ b/drivers/net/wireless/ath/ath12k/hal.h @@ -732,6 +732,7 @@ struct hal_rx_desc_data { is_decrypted:1, ip_csum_fail:1, l4_csum_fail:1, + l4_csum_checked:1, is_first_msdu:1, is_last_msdu:1, mesh_ctrl_present:1, diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c index 473887ed4bb1..fa591a03ecef 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c @@ -344,7 +344,16 @@ int ath12k_wifi7_dp_rx_tid_delete_handler(struct ath12k_base *ab, static void ath12k_wifi7_dp_rx_h_csum_offload(struct sk_buff *msdu, struct hal_rx_desc_data *rx_info) { - msdu->ip_summed = (rx_info->ip_csum_fail || rx_info->l4_csum_fail) ? + /* + * The failure bits only report a checksum the hardware computed, so + * they are also clear for a frame it did not check: anything but a + * TCP or UDP frame whose headers it parsed, and an IP fragment. A + * frame reassembled from 802.11 fragments keeps the descriptor of its + * first fragment, which does not describe the later ones. + */ + msdu->ip_summed = (ATH12K_SKB_RXCB(msdu)->is_frag || + rx_info->ip_csum_fail || rx_info->l4_csum_fail || + !rx_info->l4_csum_checked) ? CHECKSUM_NONE : CHECKSUM_UNNECESSARY; } diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hal_qcc2072.c b/drivers/net/wireless/ath/ath12k/wifi7/hal_qcc2072.c index bad2b60409d9..10a8e3e78fdf 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hal_qcc2072.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/hal_qcc2072.c @@ -347,6 +347,16 @@ static bool ath12k_hal_rx_h_l4_cksum_fail_qcc2072(struct hal_rx_desc *desc) RX_MSDU_END_INFO13_TCP_UDP_CKSUM_FAIL); } +static bool ath12k_hal_rx_h_l4_csum_checked_qcc2072(struct hal_rx_desc *desc) +{ + u32 info11 = __le32_to_cpu(desc->u.qcc2072.msdu_end.info11); + + return (info11 & (RX_MSDU_END_INFO11_TCP | RX_MSDU_END_INFO11_UDP)) && + !(info11 & RX_MSDU_END_INFO11_IP_FRAG) && + (info11 & RX_MSDU_END_INFO11_IP_FIXED_HDR_VALID) && + (info11 & RX_MSDU_END_INFO11_IP_TCP_UDP_HDR_VALID); +} + static bool ath12k_hal_rx_h_ip_cksum_fail_qcc2072(struct hal_rx_desc *desc) { return !!le32_get_bits(desc->u.qcc2072.msdu_end.info13, @@ -421,6 +431,7 @@ static void ath12k_hal_extract_rx_desc_data_qcc2072(struct hal_rx_desc_data *rx_ rx_desc_data->msdu_done = ath12k_hal_rx_h_msdu_done_qcc2072(ldesc); rx_desc_data->l4_csum_fail = ath12k_hal_rx_h_l4_cksum_fail_qcc2072(ldesc); rx_desc_data->ip_csum_fail = ath12k_hal_rx_h_ip_cksum_fail_qcc2072(ldesc); + rx_desc_data->l4_csum_checked = ath12k_hal_rx_h_l4_csum_checked_qcc2072(ldesc); rx_desc_data->is_decrypted = ath12k_hal_rx_h_is_decrypted_qcc2072(ldesc); rx_desc_data->err_bitmap = ath12k_hal_rx_h_mpdu_err_qcc2072(ldesc); } diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hal_qcn9274.c b/drivers/net/wireless/ath/ath12k/wifi7/hal_qcn9274.c index 0f85ae69b5e0..659d74a85764 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hal_qcn9274.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/hal_qcn9274.c @@ -872,6 +872,17 @@ bool ath12k_hal_rx_h_l4_cksum_fail_qcn9274(struct hal_rx_desc *desc) RX_MSDU_END_INFO13_TCP_UDP_CKSUM_FAIL); } +static inline +bool ath12k_hal_rx_h_l4_csum_checked_qcn9274(struct hal_rx_desc *desc) +{ + u32 info11 = __le32_to_cpu(desc->u.qcn9274_compact.msdu_end.info11); + + return (info11 & (RX_MSDU_END_INFO11_TCP | RX_MSDU_END_INFO11_UDP)) && + !(info11 & RX_MSDU_END_INFO11_IP_FRAG) && + (info11 & RX_MSDU_END_INFO11_IP_FIXED_HDR_VALID) && + (info11 & RX_MSDU_END_INFO11_IP_TCP_UDP_HDR_VALID); +} + static inline bool ath12k_hal_rx_h_ip_cksum_fail_qcn9274(struct hal_rx_desc *desc) { @@ -1042,6 +1053,7 @@ void ath12k_hal_extract_rx_desc_data_qcn9274(struct hal_rx_desc_data *rx_desc_da rx_desc_data->msdu_done = ath12k_hal_rx_h_msdu_done_qcn9274(ldesc); rx_desc_data->l4_csum_fail = ath12k_hal_rx_h_l4_cksum_fail_qcn9274(ldesc); rx_desc_data->ip_csum_fail = ath12k_hal_rx_h_ip_cksum_fail_qcn9274(ldesc); + rx_desc_data->l4_csum_checked = ath12k_hal_rx_h_l4_csum_checked_qcn9274(ldesc); rx_desc_data->is_decrypted = ath12k_hal_rx_h_is_decrypted_qcn9274(ldesc); rx_desc_data->err_bitmap = ath12k_hal_rx_h_mpdu_err_qcn9274(ldesc); } diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hal_wcn7850.c b/drivers/net/wireless/ath/ath12k/wifi7/hal_wcn7850.c index 2d66d71d1b9b..6e103f49bb9f 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hal_wcn7850.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/hal_wcn7850.c @@ -485,6 +485,17 @@ bool ath12k_hal_rx_h_l4_cksum_fail_wcn7850(struct hal_rx_desc *desc) RX_MSDU_END_INFO13_TCP_UDP_CKSUM_FAIL); } +static inline +bool ath12k_hal_rx_h_l4_csum_checked_wcn7850(struct hal_rx_desc *desc) +{ + u32 info11 = __le32_to_cpu(desc->u.wcn7850.msdu_end.info11); + + return (info11 & (RX_MSDU_END_INFO11_TCP | RX_MSDU_END_INFO11_UDP)) && + !(info11 & RX_MSDU_END_INFO11_IP_FRAG) && + (info11 & RX_MSDU_END_INFO11_IP_FIXED_HDR_VALID) && + (info11 & RX_MSDU_END_INFO11_IP_TCP_UDP_HDR_VALID); +} + static inline bool ath12k_hal_rx_h_ip_cksum_fail_wcn7850(struct hal_rx_desc *desc) { @@ -638,6 +649,7 @@ void ath12k_hal_extract_rx_desc_data_wcn7850(struct hal_rx_desc_data *rx_desc_da rx_desc_data->msdu_done = ath12k_hal_rx_h_msdu_done_wcn7850(ldesc); rx_desc_data->l4_csum_fail = ath12k_hal_rx_h_l4_cksum_fail_wcn7850(ldesc); rx_desc_data->ip_csum_fail = ath12k_hal_rx_h_ip_cksum_fail_wcn7850(ldesc); + rx_desc_data->l4_csum_checked = ath12k_hal_rx_h_l4_csum_checked_wcn7850(ldesc); rx_desc_data->is_decrypted = ath12k_hal_rx_h_is_decrypted_wcn7850(ldesc); rx_desc_data->err_bitmap = ath12k_hal_rx_h_mpdu_err_wcn7850(ldesc); } -- 2.53.0 With Ethernet decap (frame_mode=2), ath11k hands mac80211 the Ethernet source address of a decapped MSDU without comparing it with the address of the station that sent it. ieee80211_rx_8023() delivers the frame under that source, and for EAPOL and decrypted group frames ath11k_dp_rx_h_undecap_eth() writes it into the 802.11 header it rebuilds. mac80211 compares the source with the station only for the A-MSDU subframes it deaggregates itself (check_sa in __ieee80211_rx_h_amsdu()). On IPQ8074 hw2.0 with firmware WLAN.HK.2.12-01460, the firmware passes the fourth address of a 4-address data frame through as the Ethernet source, also from a station the AP has not set up for 4-address use. A station associated to the AP can therefore turn on 4-address mode on its own side and send frames under any source address, and a bridge on the AP learns that address on the Wi-Fi port. An ath10k station sent 200 broadcasts with a forged source this way, and all 200 reached the AP's bridge. On an AP vdev, drop an Ethernet II frame from a peer that does not use four addresses when its source is not the peer's address. Frames of a 4-address station keep their path, as do frames on a station vdev, whose sources are the hosts behind the access point. ath11k_dp_rx_h_mpdu() looks the peer up under base_lock already; it now returns an error for such a frame and both callers free it. ath12k already hands such 4-address frames to mac80211 as 802.11 frames (ath12k_dp_rx_h_undecap()), and mac80211 drops them on an AP interface. Found by an LLM review (Claude) of the code; the trigger above was then reproduced on hardware. Fixes: 2167fa606c0f ("ath11k: Add support for RX decapsulation offload") Signed-off-by: Julius Bairaktaris --- v2: discovery line reworded. drivers/net/wireless/ath/ath11k/dp_rx.c | 58 ++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c index a2c359cc8e92..516856c531a9 100644 --- a/drivers/net/wireless/ath/ath11k/dp_rx.c +++ b/drivers/net/wireless/ath/ath11k/dp_rx.c @@ -2291,13 +2291,47 @@ ath11k_dp_rx_h_find_peer(struct ath11k_base *ab, struct sk_buff *msdu) return peer; } -static void ath11k_dp_rx_h_mpdu(struct ath11k *ar, - struct sk_buff *msdu, - struct hal_rx_desc *rx_desc, - struct ieee80211_rx_status *rx_status) +/* + * With Ethernet decap the hardware takes the source address from the frame, + * for a four-address frame from address 4, which a station can send although + * the access point did not set it up for four addresses, and mac80211's 802.3 + * path and ath11k_dp_rx_h_undecap_eth() take it as the address of the station. + * An access point takes no other source from a station that does not use four + * addresses. + */ +static bool ath11k_dp_rx_h_eth_sa_valid(struct ath11k_base *ab, + struct ath11k_peer *peer, + struct hal_rx_desc *rx_desc, + struct sk_buff *msdu) +{ + struct ath11k_sta *arsta; + struct ethhdr *eth; + + lockdep_assert_held(&ab->base_lock); + + if (ath11k_dp_rx_h_msdu_start_decap_type(ab, rx_desc) != + DP_RX_DECAP_TYPE_ETHERNET2_DIX || !peer->sta) + return true; + + arsta = ath11k_sta_to_arsta(peer->sta); + if (arsta->arvif->vdev_type != WMI_VDEV_TYPE_AP || arsta->use_4addr_set) + return true; + + if (msdu->len < ETH_HLEN) + return false; + + eth = (struct ethhdr *)msdu->data; + return ether_addr_equal(eth->h_source, peer->addr); +} + +static int ath11k_dp_rx_h_mpdu(struct ath11k *ar, + struct sk_buff *msdu, + struct hal_rx_desc *rx_desc, + struct ieee80211_rx_status *rx_status) { bool fill_crypto_hdr; enum hal_encrypt_type enctype; + bool sa_valid = true; bool is_decrypted = false; struct ath11k_skb_rxcb *rxcb; struct ieee80211_hdr *hdr; @@ -2322,11 +2356,16 @@ static void ath11k_dp_rx_h_mpdu(struct ath11k *ar, enctype = peer->sec_type_grp; else enctype = peer->sec_type; + sa_valid = ath11k_dp_rx_h_eth_sa_valid(ar->ab, peer, rx_desc, + msdu); } else { enctype = ath11k_dp_rx_h_mpdu_start_enctype(ar->ab, rx_desc); } spin_unlock_bh(&ar->ab->base_lock); + if (!sa_valid) + return -EINVAL; + rx_attention = ath11k_dp_rx_get_attention(ar->ab, rx_desc); err_bitmap = ath11k_dp_rx_h_attn_mpdu_err(rx_attention); if (enctype != HAL_ENCRYPT_TYPE_OPEN && !err_bitmap) @@ -2360,13 +2399,15 @@ static void ath11k_dp_rx_h_mpdu(struct ath11k *ar, enctype, rx_status, is_decrypted); if (!is_decrypted || fill_crypto_hdr) - return; + return 0; if (ath11k_dp_rx_h_msdu_start_decap_type(ar->ab, rx_desc) != DP_RX_DECAP_TYPE_ETHERNET2_DIX) { hdr = (void *)msdu->data; hdr->frame_control &= ~__cpu_to_le16(IEEE80211_FCTL_PROTECTED); } + + return 0; } static void ath11k_dp_rx_h_rate(struct ath11k *ar, struct hal_rx_desc *rx_desc, @@ -2664,7 +2705,9 @@ static int ath11k_dp_rx_process_msdu(struct ath11k *ar, } ath11k_dp_rx_h_ppdu(ar, rx_desc, rx_status); - ath11k_dp_rx_h_mpdu(ar, msdu, rx_desc, rx_status); + ret = ath11k_dp_rx_h_mpdu(ar, msdu, rx_desc, rx_status); + if (ret) + goto free_out; rx_status->flag |= RX_FLAG_SKIP_MONITOR | RX_FLAG_DUP_VALIDATED; @@ -4056,7 +4099,8 @@ static int ath11k_dp_rx_h_null_q_desc(struct ath11k *ar, struct sk_buff *msdu, ath11k_dp_rx_h_ppdu(ar, desc, status); - ath11k_dp_rx_h_mpdu(ar, msdu, desc, status); + if (ath11k_dp_rx_h_mpdu(ar, msdu, desc, status)) + return -EINVAL; rxcb->tid = ath11k_dp_rx_h_mpdu_start_tid(ar->ab, desc); -- 2.53.0 ath11k_dp_rx_process_received_packets() keeps one ieee80211_rx_status for all MSDUs of a radio that a REO reap returns, and ath11k_dp_rx_h_mpdu() fills it for each of them. It clears RX_FLAG_DECRYPTED, RX_FLAG_IV_STRIPPED and RX_FLAG_MMIC_STRIPPED of the MSDU before, but not the other flags it sets for a decrypted MSDU: RX_FLAG_MIC_STRIPPED and RX_FLAG_ICV_STRIPPED for a group-addressed one, RX_FLAG_PN_VALIDATED for a unicast one. A decrypted group-addressed MSDU that follows a decrypted unicast MSDU of the same radio in one reap would therefore reach mac80211 with RX_FLAG_PN_VALIDATED, although the hardware checks the PN of unicast frames only. ieee80211_crypto_ccmp_decrypt() and ieee80211_crypto_gcmp_decrypt() then skip the replay check of the group key. On IPQ8074 hw2.0 with WLAN.HK.2.12-01460 this is not reachable: the firmware releases group-addressed MSDUs through the REO error path, with error code DESC_ADDR_ZERO, and ath11k_dp_rx_wbm_err() gives each of them a receive status of its own, so no reap carries the flags of a unicast MSDU into a group-addressed one. An ath11k station under unicast load received 29011 group-addressed MSDUs there, and none of them entered ath11k_dp_rx_h_mpdu() with RX_FLAG_PN_VALIDATED already set. If a chip or firmware delivers group-addressed MSDUs through the REO destination ring, a radio in range that recorded a group-addressed data frame of the network could send it again, without any key, while the receiver gets unicast data, and the station or mesh point would accept the copy. Clear the three flags with the other per-MPDU flags. Found by an LLM review (Claude) of the code. Fixes: 2167fa606c0f ("ath11k: Add support for RX decapsulation offload") Signed-off-by: Julius Bairaktaris --- v2: discovery line reworded. drivers/net/wireless/ath/ath11k/dp_rx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c index 516856c531a9..9f6872f2c8e1 100644 --- a/drivers/net/wireless/ath/ath11k/dp_rx.c +++ b/drivers/net/wireless/ath/ath11k/dp_rx.c @@ -2376,7 +2376,10 @@ static int ath11k_dp_rx_h_mpdu(struct ath11k *ar, RX_FLAG_MMIC_ERROR | RX_FLAG_DECRYPTED | RX_FLAG_IV_STRIPPED | - RX_FLAG_MMIC_STRIPPED); + RX_FLAG_MMIC_STRIPPED | + RX_FLAG_MIC_STRIPPED | + RX_FLAG_ICV_STRIPPED | + RX_FLAG_PN_VALIDATED); if (err_bitmap & DP_RX_MPDU_ERR_FCS) rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; -- 2.53.0 ath12k_wifi7_dp_rx_process_received_packets() keeps one ieee80211_rx_status for all MSDUs that a REO reap returns, and ath12k_wifi7_dp_rx_h_mpdu() fills it for each of them. As in ath11k, it clears RX_FLAG_DECRYPTED, RX_FLAG_IV_STRIPPED and RX_FLAG_MMIC_STRIPPED of the MSDU before, but not RX_FLAG_MIC_STRIPPED, RX_FLAG_ICV_STRIPPED and RX_FLAG_PN_VALIDATED, which it also sets for a decrypted MSDU. ath12k_get_dot11_hdr_from_rx_desc() drops RX_FLAG_PN_VALIDATED from a group-addressed MSDU that was decapped to Ethernet, but a decrypted group-addressed MSDU in native Wi-Fi decap that follows a decrypted unicast MSDU in one reap would reach mac80211 with RX_FLAG_PN_VALIDATED, and ieee80211_crypto_ccmp_decrypt() and ieee80211_crypto_gcmp_decrypt() then skip the replay check of the group key. Whether a reap holds such a pair depends, as in ath11k, on whether the firmware delivers group-addressed MSDUs through the REO destination ring. Clear the three flags with the other per-MPDU flags. Found by an LLM review (Claude) of the code. Fixes: d889913205cf ("wifi: ath12k: driver for Qualcomm Wi-Fi 7 devices") Signed-off-by: Julius Bairaktaris --- v2: discovery line reworded. drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c index fa591a03ecef..e37353445749 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c @@ -414,7 +414,10 @@ static int ath12k_wifi7_dp_rx_h_mpdu(struct ath12k_pdev_dp *dp_pdev, RX_FLAG_MMIC_ERROR | RX_FLAG_DECRYPTED | RX_FLAG_IV_STRIPPED | - RX_FLAG_MMIC_STRIPPED); + RX_FLAG_MMIC_STRIPPED | + RX_FLAG_MIC_STRIPPED | + RX_FLAG_ICV_STRIPPED | + RX_FLAG_PN_VALIDATED); if (err_bitmap & HAL_RX_MPDU_ERR_FCS) rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; -- 2.53.0 Since commit c4aa897fe234 ("wifi: ath12k: Handle DP_RX_DECAP_TYPE_8023 type in Rx path"), ath12k_dp_rx_h_undecap() sets RX_FLAG_8023 in the receive status that ath12k_wifi7_dp_rx_process_received_packets() keeps for all MSDUs of a REO reap. Before, ath12k_dp_rx_deliver_msdu() set it in the copy it hands to mac80211. Nothing clears it, so every MSDU after the first one delivered as 802.3 reaches mac80211 with RX_FLAG_8023, including those that carry an 802.11 header: ath12k_dp_rx_h_undecap() rebuilds one for EAPOL frames, for decrypted group-addressed frames and for frames from a 3-address peer with both DS bits set, and native Wi-Fi decap delivers one. mac80211 hands such a frame to __ieee80211_rx_handle_8023(), which drops it when the station has no fast-RX state, as before its 4-way handshake completes, and otherwise handles it as an Ethernet frame whose addresses and EtherType are bytes of the 802.11 header. An EAPOL frame that follows a data frame of any station in the same reap is lost this way, and so is a decrypted group-addressed frame. Clear RX_FLAG_8023 with the other per-MPDU flags in ath12k_wifi7_dp_rx_h_mpdu(), before ath12k_dp_rx_h_undecap() sets it. Found by an LLM review (Claude) of the code. Fixes: c4aa897fe234 ("wifi: ath12k: Handle DP_RX_DECAP_TYPE_8023 type in Rx path") Signed-off-by: Julius Bairaktaris --- v2: discovery line reworded. drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c index e37353445749..b74ffcd94a87 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c @@ -417,7 +417,8 @@ static int ath12k_wifi7_dp_rx_h_mpdu(struct ath12k_pdev_dp *dp_pdev, RX_FLAG_MMIC_STRIPPED | RX_FLAG_MIC_STRIPPED | RX_FLAG_ICV_STRIPPED | - RX_FLAG_PN_VALIDATED); + RX_FLAG_PN_VALIDATED | + RX_FLAG_8023); if (err_bitmap & HAL_RX_MPDU_ERR_FCS) rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; -- 2.53.0