Linux wireless drivers development
 help / color / mirror / Atom feed
* [PATCH] wifi: mt76: sdio: check the RX packet length in mt76s_rx_run_queue()
@ 2026-11-19 12:49 Maoyi Xie
  2026-11-19 16:49 ` Lorenzo Bianconi
  0 siblings, 1 reply; 2+ messages in thread
From: Maoyi Xie @ 2026-11-19 12:49 UTC (permalink / raw)
  To: Felix Fietkau, Lorenzo Bianconi, Ryder Lee
  Cc: Shayne Chen, Sean Wang, Matthias Brugger,
	AngeloGioacchino Del Regno, linux-wireless, linux-arm-kernel,
	linux-mediatek, stable

mt76s_rx_run_queue() reads the packets that the chip announced in the
interrupt status into one buffer. It then takes the length of each
packet from the first word of the packet and does not compare it with
the bytes read. A larger length can make the driver read TX status
records past the end of the buffer and build an skb that extends past
it.

Stop at a packet that does not fit in the bytes read.

Found with a CodeQL-based static analysis tool that we are developing.
Reproduced in a userspace harness under ASan, which reports no such
read with this patch. Not tested on hardware, only compile-tested with
W=1 on next-20261116.

Fixes: dacf0acfe2ce ("mt76: sdio: extend sdio module to support CONNAC2")
Cc: stable@vger.kernel.org
Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
I used an LLM to help write the harness and this patch.

 drivers/net/wireless/mediatek/mt76/sdio_txrx.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
index 3f314e8e1e69f92..86dd1165d2c7f1f 100644
--- a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
+++ b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
@@ -127,6 +127,8 @@ mt76s_rx_run_queue(struct mt76_dev *dev, enum mt76_rxq_id qid,
 
 		/* parse rxd to get the actual packet length */
 		len = le32_get_bits(rxd[0], GENMASK(15, 0));
+		if (len > end - buf)
+			break;
 
 		/* Optimized path for TXS */
 		if (!dev->drv->rx_check || dev->drv->rx_check(dev, buf, len)) {

base-commit: 7e1392a42ea288d70a266f6553fe06f57f8647ea
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] wifi: mt76: sdio: check the RX packet length in mt76s_rx_run_queue()
  2026-11-19 12:49 [PATCH] wifi: mt76: sdio: check the RX packet length in mt76s_rx_run_queue() Maoyi Xie
@ 2026-11-19 16:49 ` Lorenzo Bianconi
  0 siblings, 0 replies; 2+ messages in thread
From: Lorenzo Bianconi @ 2026-11-19 16:49 UTC (permalink / raw)
  To: Maoyi Xie
  Cc: Felix Fietkau, Ryder Lee, Shayne Chen, Sean Wang,
	Matthias Brugger, AngeloGioacchino Del Regno, linux-wireless,
	linux-arm-kernel, linux-mediatek, stable

[-- Attachment #1: Type: text/plain, Size: 2481 bytes --]

> mt76s_rx_run_queue() reads the packets that the chip announced in the
> interrupt status into one buffer. It then takes the length of each
> packet from the first word of the packet and does not compare it with
> the bytes read. A larger length can make the driver read TX status
> records past the end of the buffer and build an skb that extends past
> it.
> 
> Stop at a packet that does not fit in the bytes read.
> 
> Found with a CodeQL-based static analysis tool that we are developing.
> Reproduced in a userspace harness under ASan, which reports no such
> read with this patch. Not tested on hardware, only compile-tested with
> W=1 on next-20261116.
> 
> Fixes: dacf0acfe2ce ("mt76: sdio: extend sdio module to support CONNAC2")
> Cc: stable@vger.kernel.org
> Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
> ---
> I used an LLM to help write the harness and this patch.
> 
>  drivers/net/wireless/mediatek/mt76/sdio_txrx.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
> index 3f314e8e1e69f92..86dd1165d2c7f1f 100644
> --- a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
> +++ b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
> @@ -127,6 +127,8 @@ mt76s_rx_run_queue(struct mt76_dev *dev, enum mt76_rxq_id qid,
>  
>  		/* parse rxd to get the actual packet length */
>  		len = le32_get_bits(rxd[0], GENMASK(15, 0));
> +		if (len > end - buf)
> +			break;
>  
>  		/* Optimized path for TXS */
>  		if (!dev->drv->rx_check || dev->drv->rx_check(dev, buf, len)) {
> 
> base-commit: 7e1392a42ea288d70a266f6553fe06f57f8647ea
> -- 
> 2.34.1
> 

I do not think this patch is correct since we actually consume just len -
MT_SKB_HEAD_LEN bytes at most, right? I guess we should add something similar
to the patch below, what do you think?

Regards,
Lorenzo

diff --git a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
index 3f314e8e1e69..4f01d239e0ac 100644
--- a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
+++ b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
@@ -62,6 +62,9 @@ mt76s_build_rx_skb(void *data, int data_len, int buf_len)
 	int len = min_t(int, data_len, MT_SKB_HEAD_LEN);
 	struct sk_buff *skb;
 
+	if (data_len > len && data_len - len > buf_len)
+		return NULL;
+
 	skb = alloc_skb(len, GFP_KERNEL);
 	if (!skb)
 		return NULL;

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-19 16:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 12:49 [PATCH] wifi: mt76: sdio: check the RX packet length in mt76s_rx_run_queue() Maoyi Xie
2026-11-19 16:49 ` Lorenzo Bianconi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox