ath10k_htt_rx_h_rx_offload() validates that the offloaded MSDU fits the skb tailroom with if (skb_tailroom(msdu) < __le16_to_cpu(rx->msdu_len)) then appends the payload with skb_put(msdu, msdu_len) and realigns it: offset = 4 - ((unsigned long)msdu->data & 3); /* 1..4 */ skb_put(msdu, offset); memmove(msdu->data + offset, msdu->data, msdu->len); skb_pull(msdu, offset); The check accounts for neither the alignment skb_put() nor the memmove(). Two things go wrong, at adjacent values of msdu_len. Let R be the tailroom left after the meta header is pulled; the RX buffers are 8-aligned at fill and the meta header is 7 bytes, so in practice offset is 1. - At msdu_len == R the payload skb_put() fills the buffer to the end, and the following skb_put(msdu, offset) advances the tail past it. skb_put() calls skb_over_panic() -> BUG() before anything is copied: a device-triggered kernel BUG (denial of service). - At msdu_len == R - offset both puts fit, but msdu->len is now msdu_len + offset, so memmove(msdu->data + offset, msdu->data, msdu->len) writes offset bytes past the end of the buffer, onto the first byte(s) of the adjacent struct skb_shared_info. This is a real out-of-bounds write (CWE-787) of offset bytes (one byte in the geometry above). The byte written there is copied from the last byte of the DMA-mapped buffer, so its value is chip-controlled; the downstream effect of a corrupted skb_shared_info was not analysed. The msdu_len originates from the chip's HTT offload meta header, not from an over-the-air peer, and the host advertises rx_ring_bufsize = HTT_RX_BUF_SIZE (2048) to the firmware, so an honest value leaves ample margin; reaching either condition requires firmware that reports a value larger than the advertised rx_ring_bufsize. Compute offset before the length check, require msdu_len + offset bytes of tailroom so an over-long frame is dropped instead of panicking, and move only the msdu_len payload bytes (msdu->len - offset) so the memmove() stays within the buffer. This closes both the BUG and the out-of-bounds write for any offset, without relying on offset being 1. The issue was identified by static analysis and by reading the driver at v7.4-rc4. It was not triggered on real or emulated hardware; the fix was compile-tested only (drivers/net/wireless/ath/ath10k/htt_rx.o builds clean as a module on an x86_64 v7.4-rc4 config with CONFIG_ATH10K=m) and was not runtime-tested. Found with AWP (https://github.com/canonical/awp). Fixes: c545070e404b ("ath10k: implement rx reorder support") Assisted-by: Claude Opus5.5 (Frama-C) Signed-off-by: Fabrice Derepas --- drivers/net/wireless/ath/ath10k/htt_rx.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/htt_rx.c b/drivers/net/wireless/ath/ath10k/htt_rx.c index ab2d373b4..71d77ac09 100644 --- a/drivers/net/wireless/ath/ath10k/htt_rx.c +++ b/drivers/net/wireless/ath/ath10k/htt_rx.c @@ -3226,7 +3226,12 @@ static void ath10k_htt_rx_h_rx_offload(struct ath10k *ar, skb_put(msdu, sizeof(*rx)); skb_pull(msdu, sizeof(*rx)); - if (skb_tailroom(msdu) < __le16_to_cpu(rx->msdu_len)) { + /* The realignment below moves the payload forward by offset + * (1..4) bytes, so the length check must account for it too. + */ + offset = 4 - ((unsigned long)msdu->data & 3); + + if (skb_tailroom(msdu) < __le16_to_cpu(rx->msdu_len) + offset) { ath10k_warn(ar, "dropping frame: offloaded rx msdu is too long!\n"); dev_kfree_skb_any(msdu); continue; @@ -3237,11 +3242,12 @@ static void ath10k_htt_rx_h_rx_offload(struct ath10k *ar, /* Offloaded rx header length isn't multiple of 2 nor 4 so the * actual payload is unaligned. Align the frame. Otherwise * mac80211 complains. This shouldn't reduce performance much - * because these offloaded frames are rare. + * because these offloaded frames are rare. Move only the + * msdu_len payload bytes (msdu->len - offset), not the + * just-added padding, so the memmove() stays within the buffer. */ - offset = 4 - ((unsigned long)msdu->data & 3); skb_put(msdu, offset); - memmove(msdu->data + offset, msdu->data, msdu->len); + memmove(msdu->data + offset, msdu->data, msdu->len - offset); skb_pull(msdu, offset); /* FIXME: The frame is NWifi. Re-construct QoS Control base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f -- 2.53.0