Skip to contentSkip to conversation

wifi: mt76: mt7603: drop RX frame with a header gap past its end

PATCH New Maoyi Xie 1 participant 1 message Nov 30

Subsystems (2)
lore
Share & tools
lore

Maoyi Xie

author
#0 lore raw

PATCH 1/1 wifi: mt76: mt7603: drop RX frame with a header gap past its end

mt7603_mac_fill_rx() does not check the header gap against the linear data of the skb. A frame of several DMA buffers is not linear, and the hardware sets the length of the first buffer. If the header gap is too large, skb_pull() hits the BUG() in __skb_pull(), or fails and leaves no headroom, so the __skb_push() in mt76_insert_ccmp_hdr() writes before skb->head.

Drop the frame if the header gap is not within the linear data.

Found with a CodeQL-based static analysis tool that we are developing. Reproduced in a userspace harness under AddressSanitizer. Not tested on hardware.

Fixes c8846e101502 ("mt76: add driver for MT7603E and MT7628/7688")

---
This is the same check as the mt7915 patch at [1], for mt7603.

I used an LLM to help write the harness and this patch.

[1] https://lore.kernel.org/linux-wireless/[email protected]/

 drivers/net/wireless/mediatek/mt76/mt7603/mac.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7603/mac.c +3 -0
index c884576c9385..a1a2aa5b47a0 100644
@@ -692,6 +692,9 @@ mt7603_mac_fill_rx(struct mt7603_dev *dev, struct sk_buff *skb)
 		return -EINVAL;
 	}
 
+	if ((u8 *)rxd - skb->data + 2 * remove_pad >= skb_headlen(skb))
+		return -EINVAL;
+
 	skb_pull(skb, (u8 *)rxd - skb->data + 2 * remove_pad);
 
 	if (insert_ccmp_hdr) {

base-commit: 87868333220b542ff6237c93abdca84c71337f59

Signature · 1 line
2.34.1