staging: rtl8723bs: fix OOB write in HT_caps_handler()
PATCH 1/2 staging: rtl8723bs: fix OOB write in HT_caps_handler()
From: Alexandru Hossu <[email protected]>
HT_caps_handler() iterates pIE->length bytes and writes into HT_caps.u.HT_cap[], which is a fixed 26-byte array (sizeof struct HT_caps_element). Because pIE->length is a raw u8 from an over-the-air 802.11 AssocResponse frame and is never validated, a malicious AP can set it up to 255, causing up to 229 bytes of out-of-bounds writes into adjacent fields of struct mlme_ext_info.
The parallel function HT_info_handler() already carries the correct guard:
if (pIE->length > sizeof(struct HT_info_element))
return;
Apply the same pattern to HT_caps_handler().
--- drivers/staging/rtl8723bs/core/rtw_wlan_util.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +3 -0
@@ -934,6 +934,9 @@ void HT_caps_handler(struct adapter *padapter, struct ndis_80211_var_ie *pIE)if (phtpriv->ht_option == false)return ; +if (pIE->length >sizeof (struct HT_caps_element )) +return ; + pmlmeinfo->HT_caps_enable =1 ;for (i =0 ; i < (pIE->length); i++) {
Signature · 1 line
2.53.0
PATCH 2/2 staging: rtl8723bs: fix OOB read in OnAssocRsp() IE loop
From: Alexandru Hossu <[email protected]>
The IE parsing loop in OnAssocRsp() advances by (pIE->length + 2) each iteration but only guards on i < pkt_len. When a malicious AP sends an AssocResponse whose last IE has only one byte remaining in the frame (the element_id byte lands at pkt_len-1), the loop reads pIE->length from pframe[pkt_len], which is one byte past the allocated receive buffer.
Additionally, even when the header bytes are in bounds, pIE->length itself can extend the data window beyond pkt_len, silently passing a truncated IE to the handler functions.
Add two guards at the top of the loop body:
1. Break if fewer than sizeof(*pIE) bytes remain (can't read the header).
2. Break if the IE's declared data extends past pkt_len.
--- drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +4 -0
@@ -1400,7 +1400,11 @@ unsigned int OnAssocRsp(struct adapter *padapter, union recv_frame *precv_frame)/* to handle HT, WMM, rate adaptive, update MAC reg */ /* for not to handle the synchronous IO in the tasklet */ for (i = (6 +WLAN_HDR_A3_LEN ); i < pkt_len;) { +if (i +sizeof (*pIE) > pkt_len) +break ; pIE = (struct ndis_80211_var_ie *)(pframe + i); +if (i +sizeof (*pIE) + pIE->length > pkt_len) +break ;switch (pIE->element_id) {case WLAN_EID_VENDOR_SPECIFIC :
Signature · 1 line
2.53.0
Greg KH
maintainerRe: [PATCH 2/2] staging: rtl8723bs: fix OOB read in OnAssocRsp() IE loop
Quoted 41 lines · Alexandru Hossu
From: Alexandru Hossu <[email protected]>
The IE parsing loop in
OnAssocRsp()advances by (pIE->length+ 2) each iteration but only guards on i <pkt_len. When a malicious AP sends an AssocResponse whose last IE has only one byte remaining in the frame (theelement_idbyte lands at pkt_len-1), the loop readspIE->lengthfrom pframe[pkt_len], which is one byte past the allocated receive buffer.Additionally, even when the header bytes are in bounds,
pIE->lengthitself can extend the data window beyondpkt_len, silently passing a truncated IE to the handler functions.Add two guards at the top of the loop body:
1. Break if fewer thansizeof(*pIE)bytes remain (can't read the header).
2. Break if the IE's declared data extends pastpkt_len.Signed-off-by Alexandru Hossu <[email protected]>--- drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +4
-0@@ -1400,7 +1400,11 @@ unsigned int OnAssocRsp(struct adapter *padapter, union recv_frame *precv_frame)/* to handle HT, WMM, rate adaptive, update MAC reg */ /* for not to handle the synchronous IO in the tasklet */ for (i = (6 +WLAN_HDR_A3_LEN ); i < pkt_len;) { +if (i +sizeof (*pIE) > pkt_len) +break ; pIE = (struct ndis_80211_var_ie *)(pframe + i); +if (i +sizeof (*pIE) + pIE->length > pkt_len) +break ;switch (pIE->element_id) {case WLAN_EID_VENDOR_SPECIFIC :Signature · 1 line
2.53.0
Where is patch 1/2?
I'm totally lost...
greg k-h
Sorry for the noise — the previous series was sent with the wrong From/Signed-off-by (university address instead of personal Gmail). Please ignore patches 1/2 and 2/2 from Message-ID <[email protected]>. Resending the correct series now.
Alexandru