Skip to contentSkip to conversation

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

PATCH Superseded Tristan Madani 2 participants 3 messages Apr 21 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:
- 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(+)
drivers/net/wireless/realtek/rtw89/core.h +3 -0
index XXXXXXX..XXXXXXX 100644
@@ -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]);
 }
Signature · 1 line
2.47.3
#1 lore raw

drivers/net/wireless/realtek/rtw89/core.h static inline struct rtw89_sta_link * · line 6441

Quoted 13 lines · Tristan Madani
drivers/net/wireless/realtek/rtw89/core.h +3 -0
index XXXXXXX..XXXXXXX 100644
@@ -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]);
 }

Also, I have no idea how you're generating these patches, but please don't do whatever you're doing.

You have "X-Mailer: git-send-email 2.47.3" in there, but there's no way git would have created such corrupt patches. Also the "index XXXXX" thing seems to point to some (fairly pointless since it's just hashes) post-processing.

Please stop sending patches until you've figured out how to generate patches that can actually (and reproducibly) be *applied*.

johannes

#2 lore raw
Quoted 3 lines · Johannes Berg

Please stop sending patches until you've figured out how to generate patches that can actually (and reproducibly) be *applied*.

FWIW, I've just dropped *all* of your wireless related patches except three that provably worked, you can see it here:

https://patchwork.kernel.org/project/linux-wireless/list/?submitter=221411&state=*

Feel free to resend after you figure out how your sending email path has (not even subtly) corrupted most of your patches.

johannes