mt7615_mac_fill_rx() does not check hdr_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 hdr_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. For a first fragment, mt7615_reverse_frag0_hdr_trans() reads an Ethernet header after hdr_gap, and a frame too short for it makes the skb_push() of the LLC header hit skb_under_panic(). Drop the frame if hdr_gap is not within the linear data, or if a first fragment holds no full Ethernet header there. Fixes: 04b8e65922f6 ("mt76: add mac80211 driver for MT7615 PCIe-based chipsets") Fixes: dc5399a50b45 ("mt76: reverse the first fragmented frame to 802.11") Cc: stable@vger.kernel.org Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c index ff9c16977858..52c65c50bb60 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c @@ -257,6 +257,9 @@ static int mt7615_reverse_frag0_hdr_trans(struct sk_buff *skb, u16 hdr_gap) struct ieee80211_hdr hdr; u16 frame_control; + if (skb_headlen(skb) < hdr_gap + sizeof(*eth_hdr)) + return -EINVAL; + if (le32_get_bits(rxd[1], MT_RXD1_NORMAL_ADDR_TYPE) != MT_RXD1_NORMAL_U2M) return -EINVAL; @@ -594,6 +597,9 @@ static int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb) } hdr_gap = (u8 *)rxd - skb->data + 2 * remove_pad; + if (hdr_gap >= skb_headlen(skb)) + return -EINVAL; + if (hdr_trans && ieee80211_has_morefrags(fc)) { if (mt7615_reverse_frag0_hdr_trans(skb, hdr_gap)) return -EINVAL; -- 2.47.3