[PATCH v3] wifi: rtw89: add bounds check on firmware mac_id in link lookup

Tristan Madani
2026-04-21T10:44:33Z

On Mon, 20 Apr 2026, Ping-Ke Shih wrote:
> Since this is used by data path, I prefer 'unlikely(macid >= RTW89_MAX_MAC_ID_NUM'.

Good point. v3 below adds unlikely().

---

From: Tristan Madani <tristan@talencesecurity.com>
Subject: [PATCH v3] wifi: rtw89: add bounds check on firmware mac_id in link lookup

The mac_id field in RX descriptors is 8 bits wide (0-255), but
assoc_link_on_macid[] has only RTW89_MAX_MAC_ID_NUM (128) entries.
While the driver currently assigns mac_id values below 128, the
descriptor value comes from firmware and is not validated before use
as an array index. Add a defensive bounds check in
rtw89_assoc_link_rcu_dereference() to guard against out-of-range
firmware values.

Fixes: 144c6cd24b35 ("wifi: rtw89: 8922a: configure AP_LINK_PS if FW supports")
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
Changes in v3:
- Wrap check in unlikely() since this is a data path, per
Ping-Ke Shih.

Changes in v2:
- v2 resubmission with plain-text formatting (git send-email).
Per Ping-Ke Shih: defensive framing (firmware assigns < 128
today, but descriptor field is 8-bit).

drivers/net/wireless/realtek/rtw89/core.h | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h
index XXXXXXX..XXXXXXX 100644
--- a/drivers/net/wireless/realtek/rtw89/core.h
+++ b/drivers/net/wireless/realtek/rtw89/core.h
@@ -6435,6 +6435,9 @@ static inline struct rtw89_sta_link *
rtw89_assoc_link_rcu_dereference(struct rtw89_dev *rtwdev, u8 macid)
{
+ if (unlikely(macid >= RTW89_MAX_MAC_ID_NUM))
+ return NULL;
+
return rcu_dereference(rtwdev->assoc_link_on_macid[macid]);
}
--
2.43.0