Skip to content

Commit 154828b

Browse files
cyberkunjugregkh
authored andcommitted
staging: rtl8723bs: fix out-of-bounds read in rtw_get_ie() parser
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 <knavaneeth786@gmail.com> Cc: stable <stable@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1520007 commit 154828b

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

drivers/staging/rtl8723bs/core/rtw_ieee80211.c

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

141-
if (limit < 1)
141+
if (limit < 2)
142142
return NULL;
143143

144144
p = pbuf;
145145
i = 0;
146146
*len = 0;
147-
while (1) {
147+
while (i + 2 <= limit) {
148+
tmp = *(p + 1);
149+
if (i + 2 + tmp > limit)
150+
break;
151+
148152
if (*p == index) {
149-
*len = *(p + 1);
153+
*len = tmp;
150154
return p;
151155
}
152-
tmp = *(p + 1);
156+
153157
p += (tmp + 2);
154158
i += (tmp + 2);
155-
if (i >= limit)
156-
break;
157159
}
158160
return NULL;
159161
}

0 commit comments

Comments
 (0)