wifi: mt76: bound the TXS walk by the head buffer in three drivers
Subsystems (2)
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
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.
---
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
@@ -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
PATCH 2/3 wifi: mt76: mt7915: fix out-of-bounds read in mt7915_mac_add_txs
In reply to Maoyi Xiemt7915_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.
---
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
@@ -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
PATCH 3/3 wifi: mt76: mt7996: fix out-of-bounds read in mt7996_mac_add_txs
In reply to Maoyi Xiemt7996_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.
---
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
@@ -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