Skip to contentSkip to conversation

wifi: mt76: bound the TXS walk by the head buffer in three drivers

PATCH New Maoyi Xie 1 participant 4 messages Dec 2

Subsystems (2)
lore
Share & tools
lore

Maoyi Xie

author
#0 lore raw

cover wifi: mt76: bound the TXS walk by the head buffer in three drivers

This is the same fix as the mt7921 and mt7925 patches at [1] and [2], for mt7603, mt7915 and mt7996.

Found with a CodeQL-based static analysis tool that we are developing. Each case was reproduced in a userspace harness under AddressSanitizer. Not tested on hardware. Compile-tested with W=1 on the mt76 tree.

I used an LLM to help write the harnesses and these patches.

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

Maoyi Xie (3):
wifi: mt76: mt7603: fix out-of-bounds read in mt7603_mac_add_txs
wifi: mt76: mt7915: fix out-of-bounds read in mt7915_mac_add_txs
wifi: mt76: mt7996: fix out-of-bounds read in mt7996_mac_add_txs

 drivers/net/wireless/mediatek/mt76/mt7603/dma.c | 2 +-
 drivers/net/wireless/mediatek/mt76/mt7915/mac.c | 2 +-
 drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/3 wifi: mt76: mt7603: fix out-of-bounds read in mt7603_mac_add_txs

mt7603_queue_rx_skb() walks the TXS entries up to skb->len. A frame of several DMA buffers is not linear, so skb->data only covers skb_headlen(skb) bytes, and the loop reads past the head buffer of the skb.

Bound the walk by skb_headlen(skb). For a linear skb both lengths are equal.

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

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

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

 drivers/net/wireless/mediatek/mt76/mt7603/dma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7603/dma.c +1 -1
index 491c8c937031..b7cddd3e56d8 100644
@@ -113,7 +113,7 @@ void mt7603_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
 {
 	struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76);
 	__le32 *rxd = (__le32 *)skb->data;
-	__le32 *end = (__le32 *)&skb->data[skb->len];
+	__le32 *end = (__le32 *)&skb->data[skb_headlen(skb)];
 	enum rx_pkt_type type;
 
 	type = le32_get_bits(rxd[0], MT_RXD0_PKT_TYPE);
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/3 wifi: mt76: mt7915: fix out-of-bounds read in mt7915_mac_add_txs

In reply to Maoyi Xie

mt7915_queue_rx_skb() walks the TXS entries up to skb->len. A frame of several DMA buffers is not linear, so skb->data only covers skb_headlen(skb) bytes, and the loop reads past the head buffer of the skb.

Bound the walk by skb_headlen(skb). For a linear skb both lengths are equal.

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

Fixes 3de4cb175656 ("mt76: mt7915: add support for tx status reporting")

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

 drivers/net/wireless/mediatek/mt76/mt7915/mac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +1 -1
index 334af60f543e..2265f9adb336 100644
@@ -1060,7 +1060,7 @@ void mt7915_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
 {
 	struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
 	__le32 *rxd = (__le32 *)skb->data;
-	__le32 *end = (__le32 *)&skb->data[skb->len];
+	__le32 *end = (__le32 *)&skb->data[skb_headlen(skb)];
 	enum rx_pkt_type type;
 
 	type = le32_get_bits(rxd[0], MT_RXD0_PKT_TYPE);
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH 3/3 wifi: mt76: mt7996: fix out-of-bounds read in mt7996_mac_add_txs

In reply to Maoyi Xie

mt7996_queue_rx_skb() walks the TXS entries up to skb->len. An skb of several DMA buffers from mt76_dma_rx_process() is not linear, so skb->data only covers skb_headlen(skb) bytes, and the loop reads past the head buffer of the skb.

Bound the walk by skb_headlen(skb). For a linear skb both lengths are equal.

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

Fixes 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices")

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

 drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +1 -1
index dfce362a0cc9..7a33f5ec0551 100644
@@ -1715,7 +1715,7 @@ void mt7996_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
 {
 	struct mt7996_dev *dev = container_of(mdev, struct mt7996_dev, mt76);
 	__le32 *rxd = (__le32 *)skb->data;
-	__le32 *end = (__le32 *)&skb->data[skb->len];
+	__le32 *end = (__le32 *)&skb->data[skb_headlen(skb)];
 	enum rx_pkt_type type;
 
 	type = le32_get_bits(rxd[0], MT_RXD0_PKT_TYPE);
Signature · 1 line
2.34.1