Skip to content

Commit 567e14e

Browse files
committed
wifi: cfg80211: ensure length byte is present before access
When iterating the elements here, ensure the length byte is present before checking it to see if the entire element will fit into the buffer. Longer term, we should rewrite this code using the type-safe element iteration macros that check all of this. Fixes: 0b8fb82 ("cfg80211: Parsing of Multiple BSSID information in scanning") Reported-by: Soenke Huster <[email protected]> Signed-off-by: Johannes Berg <[email protected]>
1 parent ff05d4b commit 567e14e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

net/wireless/scan.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ static size_t cfg80211_gen_new_ie(const u8 *ie, size_t ielen,
304304
tmp_old = cfg80211_find_ie(WLAN_EID_SSID, ie, ielen);
305305
tmp_old = (tmp_old) ? tmp_old + tmp_old[1] + 2 : ie;
306306

307-
while (tmp_old + tmp_old[1] + 2 - ie <= ielen) {
307+
while (tmp_old + 2 - ie <= ielen &&
308+
tmp_old + tmp_old[1] + 2 - ie <= ielen) {
308309
if (tmp_old[0] == 0) {
309310
tmp_old++;
310311
continue;
@@ -364,7 +365,8 @@ static size_t cfg80211_gen_new_ie(const u8 *ie, size_t ielen,
364365
* copied to new ie, skip ssid, capability, bssid-index ie
365366
*/
366367
tmp_new = sub_copy;
367-
while (tmp_new + tmp_new[1] + 2 - sub_copy <= subie_len) {
368+
while (tmp_new + 2 - sub_copy <= subie_len &&
369+
tmp_new + tmp_new[1] + 2 - sub_copy <= subie_len) {
368370
if (!(tmp_new[0] == WLAN_EID_NON_TX_BSSID_CAP ||
369371
tmp_new[0] == WLAN_EID_SSID)) {
370372
memcpy(pos, tmp_new, tmp_new[1] + 2);

0 commit comments

Comments
 (0)