Skip to contentSkip to conversation

wifi: rtw89: add bounds check on firmware mac_id in link lookup

PATCH In review Tristan Madani 2 participants 2 messages Apr 21 – Apr 29 Realtek wireless driver (rtw89)

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 wifi: rtw89: add bounds check on firmware mac_id in link lookup

From: Tristan Madani <[email protected]>

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")

---
Changes in v3:
- Wrap check in unlikely() since this is a data path, per Ping-Ke Shih.

Changes in v2:
- Plain-text formatting via 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(+)
drivers/net/wireless/realtek/rtw89/core.h +3 -0
index fd29dbbb120d2..05adf20a65be1 100644
@@ -6492,6 +6492,9 @@ static inline void rtw89_assoc_link_clr(struct rtw89_sta_link *rtwsta_link)
 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]);
 }
 
Signature · 1 line
2.47.3
maintainer
#1 lore raw
Quoted 10 lines · Tristan Madani

From: Tristan Madani <[email protected]>

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.

Quoted 2 lines
Fixes 144c6cd24b35 ("wifi: rtw89: 8922a: configure AP_LINK_PS if FW supports")

1 patch(es) applied to rtw-next branch of rtw.git, thanks.

6d88244bb129 wifi: rtw89: add bounds check on firmware mac_id in link lookup

---
https://github.com/pkshih/rtw.git