public inbox for linux-mediatek@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH 0/2] wifi: mt76: add missing skb length validation
@ 2026-04-13  3:31 Aviel Zohar
  2026-04-13  3:31 ` [PATCH 1/2] wifi: mt76: mt7925: validate skb length in testmode query Aviel Zohar
  2026-04-13  3:31 ` [PATCH 2/2] wifi: mt76: mt7915: validate skb length in txpower SKU query Aviel Zohar
  0 siblings, 2 replies; 3+ messages in thread
From: Aviel Zohar @ 2026-04-13  3:31 UTC (permalink / raw)
  To: linux-wireless
  Cc: linux-mediatek, nbd, lorenzo, sean.wang, ryder.lee, Aviel Zohar

This series addresses missing skb length validation in two mt76
drivers before memcpy operations on firmware MCU responses.

In both cases, the driver copies a fixed number of bytes from
skb->data without first checking that skb->len is large enough.
If the firmware returns a shorter-than-expected response (due to a
bug, partial DMA transfer, or in the case of mt7925, a malicious
USB device), the memcpy reads beyond the skb data buffer, causing
a heap buffer over-read. The over-read data is subsequently
returned to userspace.

Patch 1: mt7925 testmode - mt7925_tm_query() copies 512 bytes
(MT7925_EVT_RSP_LEN) from skb->data + 8 without verifying
skb->len >= 520. The leaked data is returned via nla_put()
through nl80211 testmode dump. Fix adds a length check before
the memcpy.

Patch 2: mt7915 txpower - mt7915_mcu_get_txpower_sku() copies
up to 322 bytes (MT7915_SKU_RATE_NUM * 2) from skb->data + 4
without verifying skb->len. The data surfaces through debugfs
(txpower_sku, txpower_path). Fix adds length checks for both
the TX_POWER_INFO_RATE and TX_POWER_INFO_PATH code paths.

Both fixes follow the same pattern: validate skb->len before
performing the memcpy, returning -EINVAL on insufficient data.

Tested by code inspection; I do not have the hardware to
run-test these changes.

Aviel Zohar (2):
  wifi: mt76: mt7925: validate skb length in testmode query
  wifi: mt76: mt7915: validate skb length in txpower SKU query

 drivers/net/wireless/mediatek/mt76/mt7925/testmode.c | 5 +++++
 drivers/net/wireless/mediatek/mt76/mt7915/mcu.c      | 8 ++++++++
 2 files changed, 13 insertions(+)

-- 
2.34.1


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

* [PATCH 1/2] wifi: mt76: mt7925: validate skb length in testmode query
  2026-04-13  3:31 [PATCH 0/2] wifi: mt76: add missing skb length validation Aviel Zohar
@ 2026-04-13  3:31 ` Aviel Zohar
  2026-04-13  3:31 ` [PATCH 2/2] wifi: mt76: mt7915: validate skb length in txpower SKU query Aviel Zohar
  1 sibling, 0 replies; 3+ messages in thread
From: Aviel Zohar @ 2026-04-13  3:31 UTC (permalink / raw)
  To: linux-wireless
  Cc: linux-mediatek, nbd, lorenzo, sean.wang, ryder.lee, Aviel Zohar

In mt7925_tm_query(), the response skb from mt76_mcu_send_and_get_msg()
is used in a memcpy without validating its length:

  memcpy(evt_resp, skb->data + 8, MT7925_EVT_RSP_LEN);

where MT7925_EVT_RSP_LEN is 512. If the firmware returns a response
shorter than 520 bytes (8 + 512), this reads beyond the skb data
buffer. The over-read data is then returned to userspace via nla_put()
in mt7925_testmode_dump().

Add a length check before the memcpy to ensure the skb contains
sufficient data.

Fixes: c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips")
Signed-off-by: Aviel Zohar <avielzohar123@gmail.com>
---
 drivers/net/wireless/mediatek/mt76/mt7925/testmode.c | 5 +++++
 1 file changed, 5 insertions(+)

--- a/drivers/net/wireless/mediatek/mt76/mt7925/testmode.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/testmode.c
@@ -105,6 +105,11 @@
 	if (ret)
 		goto out;
 
+	if (skb->len < MT7925_EVT_RSP_LEN + 8) {
+		ret = -EINVAL;
+		goto out;
+	}
+
 	memcpy((char *)evt_resp, (char *)skb->data + 8, MT7925_EVT_RSP_LEN);
 
 out:


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

* [PATCH 2/2] wifi: mt76: mt7915: validate skb length in txpower SKU query
  2026-04-13  3:31 [PATCH 0/2] wifi: mt76: add missing skb length validation Aviel Zohar
  2026-04-13  3:31 ` [PATCH 1/2] wifi: mt76: mt7925: validate skb length in testmode query Aviel Zohar
@ 2026-04-13  3:31 ` Aviel Zohar
  1 sibling, 0 replies; 3+ messages in thread
From: Aviel Zohar @ 2026-04-13  3:31 UTC (permalink / raw)
  To: linux-wireless
  Cc: linux-mediatek, nbd, lorenzo, sean.wang, ryder.lee, Aviel Zohar

In mt7915_mcu_get_txpower_sku(), the response skb from
mt76_mcu_send_and_get_msg() is used in memcpy without validating
its length:

For TX_POWER_INFO_RATE:
  memcpy(res, skb->data + 4, sizeof(res));

where sizeof(res) is MT7915_SKU_RATE_NUM * 2 = 322 bytes.

For TX_POWER_INFO_PATH:
  memcpy(txpower, skb->data + 4, len);

In both cases, if the firmware returns a response shorter than
the expected size, the memcpy reads beyond the skb data buffer.
The data surfaces to userspace via debugfs (txpower_sku and
txpower_path).

Add length checks for both code paths before the memcpy.

Signed-off-by: Aviel Zohar <avielzohar123@gmail.com>
---
 drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 8 ++++++++
 1 file changed, 8 insertions(+)

--- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
@@ -3532,10 +3532,18 @@
 	if (category == TX_POWER_INFO_RATE) {
 		s8 res[MT7915_SKU_RATE_NUM][2];
 
+		if (skb->len < sizeof(res) + 4) {
+			dev_kfree_skb(skb);
+			return -EINVAL;
+		}
 		memcpy(res, skb->data + 4, sizeof(res));
 		for (i = 0; i < len; i++)
 			txpower[i] = res[i][req.band_idx];
 	} else if (category == TX_POWER_INFO_PATH) {
+		if (skb->len < len + 4) {
+			dev_kfree_skb(skb);
+			return -EINVAL;
+		}
 		memcpy(txpower, skb->data + 4, len);
 	}


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

end of thread, other threads:[~2026-04-13  3:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-13  3:31 [PATCH 0/2] wifi: mt76: add missing skb length validation Aviel Zohar
2026-04-13  3:31 ` [PATCH 1/2] wifi: mt76: mt7925: validate skb length in testmode query Aviel Zohar
2026-04-13  3:31 ` [PATCH 2/2] wifi: mt76: mt7915: validate skb length in txpower SKU query Aviel Zohar

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