From: Jiale Yao <yaojiale02@163.com>
To: Felix Fietkau <nbd@nbd.name>,
Lorenzo Bianconi <lorenzo@kernel.org>,
Ryder Lee <ryder.lee@mediatek.com>,
Shayne Chen <shayne.chen@mediatek.com>,
Sean Wang <sean.wang@mediatek.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Hao Zhang <hao.zhang@mediatek.com>,
Quan Zhou <quan.zhou@mediatek.com>,
Rong Yan <rong.yan@mediatek.com>,
Leon Yen <leon.yen@mediatek.com>,
Nelson Yu <nelson.yu@mediatek.com>,
linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org
Subject: [PATCH 06/11] wifi: mt76: mt7925: validate register query response
Date: Tue, 20 Oct 2026 10:45:38 +0800 [thread overview]
Message-ID: <20261020024544.3101738-7-yaojiale02@163.com> (raw)
In-Reply-To: <20261020024544.3101738-1-yaojiale02@163.com>
The register query reads either a basic or RF register response without
checking its length. A truncated firmware response can cause an
out-of-bounds read.
Calculate the response size for the selected register type and reject
short responses before reading the value.
Fixes: c948b5da6bbe ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips")
Signed-off-by: Jiale Yao <yaojiale02@163.com>
---
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
index bca753d8ce71..ce860e63a108 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/mcu.c
@@ -113,7 +113,7 @@ int mt7925_mcu_regval(struct mt792x_dev *dev, u32 regidx, u32 *val, bool set)
};
} __packed * res, req;
struct sk_buff *skb;
- int ret;
+ int len, ret;
if (u32_get_bits(regidx, MT_RF_REG_HDR) == RF_REG_PREFIX) {
req.rf_reg.tag = cpu_to_le16(UNI_CMD_ACCESS_RF_REG_BASIC);
@@ -138,6 +138,17 @@ int mt7925_mcu_regval(struct mt792x_dev *dev, u32 regidx, u32 *val, bool set)
if (ret)
return ret;
+ len = sizeof(res->__rsv);
+ if (u32_get_bits(regidx, MT_RF_REG_HDR) == RF_REG_PREFIX)
+ len += sizeof(res->rf_reg);
+ else
+ len += sizeof(res->reg);
+
+ if (skb->len < len) {
+ dev_kfree_skb(skb);
+ return -EINVAL;
+ }
+
res = (void *)skb->data;
if (u32_get_bits(regidx, MT_RF_REG_HDR) == RF_REG_PREFIX)
*val = le32_to_cpu(res->rf_reg.data);
--
2.34.1
next prev parent reply other threads:[~2026-10-20 2:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 2:45 [PATCH 00/11] wifi: mt76: validate mt792x firmware data Jiale Yao
2026-10-20 2:45 ` [PATCH 01/11] wifi: mt76: mt7921: validate MCU response lengths Jiale Yao
2026-10-20 2:45 ` [PATCH 02/11] wifi: mt76: mt7921: validate EEPROM response length Jiale Yao
2026-10-20 2:45 ` [PATCH 03/11] wifi: mt76: mt7921: reject malformed TX power responses Jiale Yao
2026-10-20 2:45 ` [PATCH 04/11] wifi: mt76: mt7921: validate testmode query response Jiale Yao
2026-10-20 2:45 ` [PATCH 05/11] wifi: mt76: mt7925: validate MCU response lengths Jiale Yao
2026-10-20 2:45 ` Jiale Yao [this message]
2026-10-20 2:45 ` [PATCH 07/11] wifi: mt76: mt7925: validate EEPROM response length Jiale Yao
2026-10-20 2:45 ` [PATCH 08/11] wifi: mt76: mt7925: validate temperature " Jiale Yao
2026-10-20 2:45 ` [PATCH 09/11] wifi: mt76: mt7925: validate TX power " Jiale Yao
2026-10-20 2:45 ` [PATCH 10/11] wifi: mt76: mt7925: validate radio status response Jiale Yao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261020024544.3101738-7-yaojiale02@163.com \
--to=yaojiale02@163.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=hao.zhang@mediatek.com \
--cc=leon.yen@mediatek.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-wireless@vger.kernel.org \
--cc=lorenzo@kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=nbd@nbd.name \
--cc=nelson.yu@mediatek.com \
--cc=quan.zhou@mediatek.com \
--cc=rong.yan@mediatek.com \
--cc=ryder.lee@mediatek.com \
--cc=sean.wang@mediatek.com \
--cc=shayne.chen@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox