Skip to content

Commit a54e2b2

Browse files
cyberkunjugregkh
authored andcommitted
staging: rtl8723bs: fix out-of-bounds read in rtw_get_ie() parser
commit 154828b upstream. The Information Element (IE) parser rtw_get_ie() trusted the length byte of each IE without validating that the IE body (len bytes after the 2-byte header) fits inside the remaining frame buffer. A malformed frame can advertise an IE length larger than the available data, causing the parser to increment its pointer beyond the buffer end. This results in out-of-bounds reads or, depending on the pattern, an infinite loop. Fix by validating that (offset + 2 + len) does not exceed the limit before accepting the IE or advancing to the next element. This prevents OOB reads and ensures the parser terminates safely on malformed frames. Signed-off-by: Navaneeth K <[email protected]> Cc: stable <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f6e629d commit a54e2b2

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

drivers/staging/rtl8723bs/core/rtw_ieee80211.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,22 +140,24 @@ u8 *rtw_get_ie(u8 *pbuf, signed int index, signed int *len, signed int limit)
140140
signed int tmp, i;
141141
u8 *p;
142142

143-
if (limit < 1)
143+
if (limit < 2)
144144
return NULL;
145145

146146
p = pbuf;
147147
i = 0;
148148
*len = 0;
149-
while (1) {
149+
while (i + 2 <= limit) {
150+
tmp = *(p + 1);
151+
if (i + 2 + tmp > limit)
152+
break;
153+
150154
if (*p == index) {
151-
*len = *(p + 1);
155+
*len = tmp;
152156
return p;
153157
}
154-
tmp = *(p + 1);
158+
155159
p += (tmp + 2);
156160
i += (tmp + 2);
157-
if (i >= limit)
158-
break;
159161
}
160162
return NULL;
161163
}

0 commit comments

Comments
 (0)