[PATCH ath-next v2 1/4] wifi: ath12k: validate RX frame length before undecapsulation
Lorenzo Bianconi
lorenzo.bianconi at oss.qualcomm.com
Fri Nov 13 06:51:42 PST 2026
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 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
Fixes: d889913205cf ("wifi: ath12k: driver for Qualcomm Wi-Fi 7 devices")
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi at oss.qualcomm.com>
---
drivers/net/wireless/ath/ath12k/dp_rx.c | 86 +++++++++++++++++++--------
drivers/net/wireless/ath/ath12k/dp_rx.h | 10 ++--
drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c | 27 ++++++---
3 files changed, 85 insertions(+), 38 deletions(-)
diff --git a/drivers/net/wireless/ath/ath12k/dp_rx.c b/drivers/net/wireless/ath/ath12k/dp_rx.c
index 52838ade1b1d..6003ca901208 100644
--- a/drivers/net/wireless/ath/ath12k/dp_rx.c
+++ b/drivers/net/wireless/ath/ath12k/dp_rx.c
@@ -999,11 +999,11 @@ static void ath12k_dp_rx_h_undecap_nwifi(struct ath12k_pdev_dp *dp_pdev,
memcpy(skb_push(msdu, hdr_len), decap_hdr, hdr_len);
}
-static void ath12k_dp_rx_h_undecap_raw(struct ath12k_pdev_dp *dp_pdev,
- struct sk_buff *msdu,
- enum hal_encrypt_type enctype,
- struct ieee80211_rx_status *status,
- bool decrypted)
+static int ath12k_dp_rx_h_undecap_raw(struct ath12k_pdev_dp *dp_pdev,
+ struct sk_buff *msdu,
+ enum hal_encrypt_type enctype,
+ struct ieee80211_rx_status *status,
+ bool decrypted)
{
struct ath12k_dp *dp = dp_pdev->dp;
struct ath12k_skb_rxcb *rxcb = ATH12K_SKB_RXCB(msdu);
@@ -1014,49 +1014,75 @@ static void ath12k_dp_rx_h_undecap_raw(struct ath12k_pdev_dp *dp_pdev,
if (!rxcb->is_first_msdu ||
!(rxcb->is_first_msdu && rxcb->is_last_msdu)) {
WARN_ON_ONCE(1);
- return;
+ return 0;
}
+ if (msdu->len <= FCS_LEN)
+ return -EINVAL;
+
skb_trim(msdu, msdu->len - FCS_LEN);
if (!decrypted)
- return;
+ return 0;
hdr = (void *)msdu->data;
/* 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);
+ if (msdu->len < hdr_len + crypto_len)
+ return -EINVAL;
+
memmove(msdu->data + crypto_len, msdu->data, hdr_len);
skb_pull(msdu, crypto_len);
}
+
+ return 0;
}
static void ath12k_get_dot11_hdr_from_rx_desc(struct ath12k_pdev_dp *dp_pdev,
@@ -1143,11 +1169,11 @@ static void ath12k_dp_rx_h_undecap_eth(struct ath12k_pdev_dp *dp_pdev,
ether_addr_copy(ieee80211_get_SA(hdr), sa);
}
-void ath12k_dp_rx_h_undecap(struct ath12k_pdev_dp *dp_pdev, struct sk_buff *msdu,
- enum hal_encrypt_type enctype,
- bool decrypted,
- struct hal_rx_desc_data *rx_info,
- struct ath12k_dp_peer *peer)
+int ath12k_dp_rx_h_undecap(struct ath12k_pdev_dp *dp_pdev, struct sk_buff *msdu,
+ enum hal_encrypt_type enctype,
+ bool decrypted,
+ struct hal_rx_desc_data *rx_info,
+ struct ath12k_dp_peer *peer)
{
enum ath12k_dp_rx_decap_type decap_type = rx_info->decap_type;
struct ethhdr *ehdr;
@@ -1156,10 +1182,16 @@ void ath12k_dp_rx_h_undecap(struct ath12k_pdev_dp *dp_pdev, struct sk_buff *msdu
case DP_RX_DECAP_TYPE_NATIVE_WIFI:
ath12k_dp_rx_h_undecap_nwifi(dp_pdev, msdu, enctype, rx_info);
break;
- case DP_RX_DECAP_TYPE_RAW:
- ath12k_dp_rx_h_undecap_raw(dp_pdev, msdu, enctype, rx_info->rx_status,
- decrypted);
+ case DP_RX_DECAP_TYPE_RAW: {
+ int err;
+
+ err = ath12k_dp_rx_h_undecap_raw(dp_pdev, msdu, enctype,
+ rx_info->rx_status,
+ decrypted);
+ if (err)
+ return err;
break;
+ }
case DP_RX_DECAP_TYPE_ETHERNET2_DIX:
ehdr = (struct ethhdr *)msdu->data;
@@ -1201,6 +1233,8 @@ void ath12k_dp_rx_h_undecap(struct ath12k_pdev_dp *dp_pdev, struct sk_buff *msdu
}
rx_info->rx_status->flag |= RX_FLAG_8023;
}
+
+ return 0;
}
EXPORT_SYMBOL(ath12k_dp_rx_h_undecap);
diff --git a/drivers/net/wireless/ath/ath12k/dp_rx.h b/drivers/net/wireless/ath/ath12k/dp_rx.h
index a78efa1d9569..5bc5b28670b7 100644
--- a/drivers/net/wireless/ath/ath12k/dp_rx.h
+++ b/drivers/net/wireless/ath/ath12k/dp_rx.h
@@ -197,11 +197,11 @@ void ath12k_dp_extract_rx_desc_data(struct ath12k_hal *hal,
hal->ops->extract_rx_desc_data(rx_info, rx_desc, ldesc);
}
-void ath12k_dp_rx_h_undecap(struct ath12k_pdev_dp *dp_pdev, struct sk_buff *msdu,
- enum hal_encrypt_type enctype,
- bool decrypted,
- struct hal_rx_desc_data *rx_info,
- struct ath12k_dp_peer *peer);
+int ath12k_dp_rx_h_undecap(struct ath12k_pdev_dp *dp_pdev, struct sk_buff *msdu,
+ enum hal_encrypt_type enctype,
+ bool decrypted,
+ struct hal_rx_desc_data *rx_info,
+ struct ath12k_dp_peer *peer);
void ath12k_dp_rx_deliver_msdu(struct ath12k_pdev_dp *dp_pdev, struct napi_struct *napi,
struct sk_buff *msdu,
struct hal_rx_desc_data *rx_info);
diff --git a/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c b/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c
index 473887ed4bb1..429f826923b2 100644
--- a/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c
+++ b/drivers/net/wireless/ath/ath12k/wifi7/dp_rx.c
@@ -359,6 +359,7 @@ static int ath12k_wifi7_dp_rx_h_mpdu(struct ath12k_pdev_dp *dp_pdev,
struct ath12k_dp_peer *peer;
struct ieee80211_rx_status *rx_status = rx_info->rx_status;
u32 err_bitmap = rx_info->err_bitmap;
+ int err;
RCU_LOCKDEP_WARN(!rcu_read_lock_held(),
"dp_rx_h_mpdu called without rcu lock");
@@ -424,8 +425,10 @@ static int ath12k_wifi7_dp_rx_h_mpdu(struct ath12k_pdev_dp *dp_pdev,
}
ath12k_wifi7_dp_rx_h_csum_offload(msdu, rx_info);
- ath12k_dp_rx_h_undecap(dp_pdev, msdu, enctype, is_decrypted, rx_info,
- peer);
+ err = ath12k_dp_rx_h_undecap(dp_pdev, msdu, enctype, is_decrypted,
+ rx_info, peer);
+ if (err)
+ return err;
if (!is_decrypted || rx_info->is_mcbc)
return 0;
@@ -1059,6 +1062,11 @@ 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];
@@ -1086,9 +1094,12 @@ 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);
- ath12k_dp_rx_h_undecap(dp_pdev, msdu, HAL_ENCRYPT_TYPE_TKIP_MIC, true,
- rx_info, NULL);
- ieee80211_rx(ath12k_pdev_dp_to_hw(dp_pdev), msdu);
+ if (!ath12k_dp_rx_h_undecap(dp_pdev, msdu, HAL_ENCRYPT_TYPE_TKIP_MIC,
+ true, rx_info, NULL))
+ ieee80211_rx(ath12k_pdev_dp_to_hw(dp_pdev), msdu);
+ else
+ dev_kfree_skb_any(msdu);
+
return -EINVAL;
}
@@ -1741,8 +1752,10 @@ static bool ath12k_wifi7_dp_rx_h_tkip_mic_err(struct ath12k_pdev_dp *dp_pdev,
rx_info->rx_status->flag |= (RX_FLAG_MMIC_STRIPPED | RX_FLAG_MMIC_ERROR |
RX_FLAG_DECRYPTED);
- ath12k_dp_rx_h_undecap(dp_pdev, msdu, HAL_ENCRYPT_TYPE_TKIP_MIC, false,
- rx_info, NULL);
+ if (ath12k_dp_rx_h_undecap(dp_pdev, msdu, HAL_ENCRYPT_TYPE_TKIP_MIC,
+ false, rx_info, NULL))
+ return true;
+
return false;
}
--
2.56.0
More information about the ath12k
mailing list