Skip to contentSkip to conversation

staging: rtl8723bs: fix OOB write in HT_caps_handler()

PATCH In review Alexandru Hossu 4 participants 6 messages May 15 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rtl8723bs: fix OOB write in HT_caps_handler()

Hi Greg,

Here is the fix.

Alexandru

---

The loop in HT_caps_handler() iterates up to pIE->length times, but HT_cap[] is only 26 bytes. pIE->length comes from the HT Capability IE in the association response and can be up to 255. This lets a rogue AP write up to 229 bytes past the array using a bitwise AND into adjacent struct fields.

Clamp the iteration count to the array size.

---
 drivers/staging/rtl8723bs/core/rtw_wlan_util.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +2 -1
index 4f41f88908d7..e271d1e395a5 100644
@@ -935,7 +935,8 @@ void HT_caps_handler(struct adapter *padapter, struct ndis_80211_var_ie *pIE)
 
 	pmlmeinfo->HT_caps_enable = 1;
 
-	for (i = 0; i < (pIE->length); i++) {
+	for (i = 0; i < min_t(unsigned int, pIE->length,
+			       sizeof(pmlmeinfo->HT_caps.u.HT_cap)); i++) {
 		if (i != 2) {
 			/* Commented by Albert 2010/07/12 */
 			/* Got the endian issue here. */
#1 lore raw
Quoted 14 lines · Alexandru Hossu

Hi Greg,

Here is the fix.

Alexandru

---

The loop in HT_caps_handler() iterates up to pIE->length times, but HT_cap[] is only 26 bytes. pIE->length comes from the HT Capability IE in the association response and can be up to 255. This lets a rogue AP write up to 229 bytes past the array using a bitwise AND into adjacent struct fields.

Quoted 4 lines

Clamp the iteration count to the array size.

---

This isn't how you send a patch. Try applying your email with:
cat raw_email.txt | git am and use git log to see the problem.

Quoted 8 lines
 drivers/staging/rtl8723bs/core/rtw_wlan_util.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +0 -0
index 4f41f88908d7..e271d1e395a5 100644

drivers/staging/rtl8723bs/core/rtw_wlan_util.c void HT_caps_handler(struct adapter *padapter, struct ndis_80211_var_ie *pIE) · line 939

Quoted 6 lines
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +2 -1
@@ -935,7 +935,8 @@ void HT_caps_handler(struct adapter *padapter, struct ndis_80211_var_ie *pIE)
 
 	pmlmeinfo->HT_caps_enable = 1;
 
-	for (i = 0; i < (pIE->length); i++) {
+	for (i = 0; i < min_t(unsigned int, pIE->length,
+			       sizeof(pmlmeinfo->HT_caps.u.HT_cap)); i++) {

Just use min() instead of min_t(). They're both unsigned.

regards,
dan carpenter

maintainer
#2 lore raw
In reply to Alexandru Hossu
Quoted 26 lines · Alexandru Hossu

Hi Greg,

Here is the fix.

Alexandru

---

The loop in HT_caps_handler() iterates up to pIE->length times, but HT_cap[] is only 26 bytes. pIE->length comes from the HT Capability IE in the association response and can be up to 255. This lets a rogue AP write up to 229 bytes past the array using a bitwise AND into adjacent struct fields.

Clamp the iteration count to the array size.

---
 drivers/staging/rtl8723bs/core/rtw_wlan_util.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +0 -0
index 4f41f88908d7..e271d1e395a5 100644

drivers/staging/rtl8723bs/core/rtw_wlan_util.c void HT_caps_handler(struct adapter *padapter, struct ndis_80211_var_ie *pIE) · line 942

Quoted 9 lines
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +2 -1
@@ -935,7 +935,8 @@ void HT_caps_handler(struct adapter *padapter, struct ndis_80211_var_ie *pIE)
 
 	pmlmeinfo->HT_caps_enable = 1;
 
-	for (i = 0; i < (pIE->length); i++) {
+	for (i = 0; i < min_t(unsigned int, pIE->length,
+			       sizeof(pmlmeinfo->HT_caps.u.HT_cap)); i++) {
 		if (i != 2) {
 			/* Commented by Albert 2010/07/12 */
 			/* Got the endian issue here. */

How does this compare with this patch:

	https://lore.kernel.org/r/2026041408-grill-mahogany-d1e3@gregkh

or the others sent recently tothe staging list to fix this "issue" that the LLM tools keep tripping over?

thanks,

greg k-h

#3 lore raw
Quoted 4 lines · Greg KH

How does this compare with this patch:

    https://lore.kernel.org/r/2026041408-grill-mahogany-d1e3@gregkh

or the others sent recently to the staging list to fix this "issue" that the LLM tools keep tripping over?

Apologies to both of you. I should have checked lore and the current tree state before sending anything. The fix is already in linux-next and I sent this without looking first.

Format note taken, Dan -- will use git send-email properly next time.

Withdrawing this patch.

Alexandru

#4 lore raw
In reply to Alexandru Hossu

Was this patch written with LLM? Why is there separate text on the patch? It could have been mentioned in the cover letter.

--
Samet

Quoted 37 lines

2026. 5. 15. 오후 2:08, Alexandru Hossu <[email protected]> 작성:

Hi Greg,

Here is the fix.

Alexandru

---

The loop in HT_caps_handler() iterates up to pIE->length times, but HT_cap[] is only 26 bytes. pIE->length comes from the HT Capability IE in the association response and can be up to 255. This lets a rogue AP write up to 229 bytes past the array using a bitwise AND into adjacent struct fields.

Clamp the iteration count to the array size.

---
drivers/staging/rtl8723bs/core/rtw_wlan_util.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +2 -1
index 4f41f88908d7..e271d1e395a5 100644
@@ -935,7 +935,8 @@ void HT_caps_handler(struct adapter *padapter, struct ndis_80211_var_ie *pIE)
 
   pmlmeinfo->HT_caps_enable = 1;
 
-    for (i = 0; i < (pIE->length); i++) {
+    for (i = 0; i < min_t(unsigned int, pIE->length,
+                   sizeof(pmlmeinfo->HT_caps.u.HT_cap)); i++) {
       if (i != 2) {
           /* Commented by Albert 2010/07/12 */
           /* Got the endian issue here. */
#5 lore raw
Quoted 2 lines · M.samet Duman

Was this patch written with LLM? Why is there separate text on the patch? It could have been mentioned in the cover letter.

I was experimenting with some local tooling and clearly it didn't produce proper output. Sorry for the noise. Noted for next time.

Alexandru