[PATCH 1/3] wifi: mt76: mt7921: validate NIC capability payload lengths

From: Jiale Yao

Date: Wed Oct 28 2026 - 01:10:04 EST


The NIC capability parser checks that each declared payload fits in the
skb, but it does not ensure that the payload is large enough for the
selected capability. A truncated firmware response can therefore make
the driver read beyond the current TLV while copying fixed-size fields or
parsing capability structures.

Validate every consumed payload before accessing it and reject the
response when a known capability is shorter than its fixed data.

Fixes: dab35009fc1c ("wifi: mt76: mt7921: move connac nic capability handling to mt7921")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Jiale Yao <yaojiale02@xxxxxxx>
---
.../net/wireless/mediatek/mt76/mt7921/mcu.c | 41 +++++++++++++++----
1 file changed, 33 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
index 25638c68c468..c960648b2b61 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
@@ -521,8 +521,8 @@ static int mt7921_load_clc(struct mt792x_dev *dev, const char *fw_name)
return ret;
}

-static void mt7921_mcu_parse_tx_resource(struct mt76_dev *dev,
- struct sk_buff *skb)
+static bool mt7921_mcu_parse_tx_resource(struct mt76_dev *dev,
+ struct sk_buff *skb, int len)
{
struct mt76_sdio *sdio = &dev->sdio;
struct mt7921_tx_resource {
@@ -537,6 +537,9 @@ static void mt7921_mcu_parse_tx_resource(struct mt76_dev *dev,
u8 pad[3];
} __packed * tx_res;

+ if (len < sizeof(*tx_res))
+ return false;
+
tx_res = (struct mt7921_tx_resource *)skb->data;
sdio->sched.pse_data_quota = le32_to_cpu(tx_res->pse_data_quota);
sdio->pse_mcu_quota_max = le32_to_cpu(tx_res->pse_mcu_quota);
@@ -546,10 +549,12 @@ static void mt7921_mcu_parse_tx_resource(struct mt76_dev *dev,
sdio->sched.ple_data_quota = le32_to_cpu(tx_res->ple_data_quota);
sdio->sched.pse_page_size = le16_to_cpu(tx_res->pse_page_size);
sdio->sched.deficit = tx_res->pp_padding;
+
+ return true;
}

-static void mt7921_mcu_parse_phy_cap(struct mt76_dev *dev,
- struct sk_buff *skb)
+static bool mt7921_mcu_parse_phy_cap(struct mt76_dev *dev,
+ struct sk_buff *skb, int len)
{
struct mt7921_phy_cap {
u8 ht;
@@ -571,12 +576,17 @@ static void mt7921_mcu_parse_phy_cap(struct mt76_dev *dev,
WF0_5G
};

+ if (len < sizeof(*cap))
+ return false;
+
cap = (struct mt7921_phy_cap *)skb->data;

dev->phy.antenna_mask = BIT(cap->nss) - 1;
dev->phy.chainmask = dev->phy.antenna_mask;
dev->phy.cap.has_2ghz = cap->hw_path & BIT(WF0_24G);
dev->phy.cap.has_5ghz = cap->hw_path & BIT(WF0_5G);
+
+ return true;
}

static int mt7921_mcu_get_nic_capability(struct mt792x_phy *mphy)
@@ -620,20 +630,30 @@ static int mt7921_mcu_get_nic_capability(struct mt792x_phy *mphy)

switch (le32_to_cpu(tlv->type)) {
case MT_NIC_CAP_6G:
+ if (len < sizeof(skb->data[0]))
+ goto invalid;
+
phy->cap.has_6ghz = skb->data[0];
break;
case MT_NIC_CAP_MAC_ADDR:
+ if (len < ETH_ALEN)
+ goto invalid;
+
memcpy(phy->macaddr, (void *)skb->data, ETH_ALEN);
break;
case MT_NIC_CAP_PHY:
- mt7921_mcu_parse_phy_cap(phy->dev, skb);
+ if (!mt7921_mcu_parse_phy_cap(phy->dev, skb, len))
+ goto invalid;
break;
case MT_NIC_CAP_TX_RESOURCE:
- if (mt76_is_sdio(phy->dev))
- mt7921_mcu_parse_tx_resource(phy->dev,
- skb);
+ if (mt76_is_sdio(phy->dev) &&
+ !mt7921_mcu_parse_tx_resource(phy->dev, skb, len))
+ goto invalid;
break;
case MT_NIC_CAP_CHIP_CAP:
+ if (len < sizeof(mphy->chip_cap))
+ goto invalid;
+
memcpy(&mphy->chip_cap, (void *)skb->data, sizeof(u64));
break;
default:
@@ -641,6 +661,11 @@ static int mt7921_mcu_get_nic_capability(struct mt792x_phy *mphy)
}
skb_pull(skb, len);
}
+
+ goto out;
+
+invalid:
+ ret = -EINVAL;
out:
dev_kfree_skb(skb);

--
2.34.1