Skip to content

Commit 1463ca3

Browse files
ahossugregkh
authored andcommitted
staging: rtl8723bs: fix OOB reads in rtw_get_sec_ie(), rtw_get_wapi_ie(), and rtw_get_wps_attr()
Three IE/attribute parsing functions have missing bounds checks. rtw_get_sec_ie() and rtw_get_wapi_ie() iterate over a raw IE buffer without verifying that the header bytes (tag + length) are within the remaining buffer before reading them. Additionally, rtw_get_sec_ie() compares the 4-byte WPA OUI at cnt+2 without checking that at least 6 bytes remain, and rtw_get_wapi_ie() compares a 4-byte WAPI OUI at cnt+6 without checking that at least 10 bytes remain. rtw_get_wps_attr() reads wps_ie[0] and wps_ie+2 unconditionally at entry, before verifying that wps_ielen is large enough to contain the 6-byte WPS IE header (element_id + length + 4-byte OUI). Inside the attribute loop, get_unaligned_be16() is called on attr_ptr and attr_ptr+2 without checking that 4 bytes remain in the buffer. Add a cnt+2 bounds check before each loop body in rtw_get_sec_ie() and rtw_get_wapi_ie(), guard each multi-byte comparison with a minimum IE length requirement, add a wps_ielen < 6 early return in rtw_get_wps_attr(), and add a 4-byte bounds check in its inner loop. Fixes: 554c0a3 ("staging: Add rtl8723bs sdio wifi driver") Cc: stable <stable@kernel.org> Signed-off-by: Alexandru Hossu <hossu.alexandru@gmail.com> Link: https://patch.msgid.link/20260522004531.1038924-8-hossu.alexandru@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3bf39f7 commit 1463ca3

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

drivers/staging/rtl8723bs/core/rtw_ieee80211.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,14 @@ int rtw_get_wapi_ie(u8 *in_ie, uint in_len, u8 *wapi_ie, u16 *wapi_len)
583583
cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_);
584584

585585
while (cnt < in_len) {
586+
if (cnt + 2 > in_len)
587+
break;
588+
if (cnt + 2 + in_ie[cnt + 1] > in_len)
589+
break;
586590
authmode = in_ie[cnt];
587591

588592
if (authmode == WLAN_EID_BSS_AC_ACCESS_DELAY &&
593+
in_ie[cnt + 1] >= 8 &&
589594
(!memcmp(&in_ie[cnt + 6], wapi_oui1, 4) ||
590595
!memcmp(&in_ie[cnt + 6], wapi_oui2, 4))) {
591596
if (wapi_ie)
@@ -615,9 +620,14 @@ void rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie
615620
cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_);
616621

617622
while (cnt < in_len) {
623+
if (cnt + 2 > in_len)
624+
break;
625+
if (cnt + 2 + in_ie[cnt + 1] > in_len)
626+
break;
618627
authmode = in_ie[cnt];
619628

620629
if ((authmode == WLAN_EID_VENDOR_SPECIFIC) &&
630+
in_ie[cnt + 1] >= 4 &&
621631
(!memcmp(&in_ie[cnt + 2], &wpa_oui[0], 4))) {
622632
if (wpa_ie)
623633
memcpy(wpa_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
@@ -698,6 +708,9 @@ u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_att
698708
if (len_attr)
699709
*len_attr = 0;
700710

711+
if (wps_ielen < 6)
712+
return attr_ptr;
713+
701714
if ((wps_ie[0] != WLAN_EID_VENDOR_SPECIFIC) ||
702715
(memcmp(wps_ie + 2, wps_oui, 4))) {
703716
return attr_ptr;
@@ -708,6 +721,8 @@ u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_att
708721

709722
while (attr_ptr - wps_ie < wps_ielen) {
710723
/* 4 = 2(Attribute ID) + 2(Length) */
724+
if (attr_ptr + 4 > wps_ie + wps_ielen)
725+
break;
711726
u16 attr_id = get_unaligned_be16(attr_ptr);
712727
u16 attr_data_len = get_unaligned_be16(attr_ptr + 2);
713728
u16 attr_len = attr_data_len + 4;

0 commit comments

Comments
 (0)