Skip to content

Commit e298aa3

Browse files
Du Chengjmberg-intel
authored andcommitted
mac80211: fix skb length check in ieee80211_scan_rx()
Replace hard-coded compile-time constants for header length check with dynamic determination based on the frame type. Otherwise, we hit a validation WARN_ON in cfg80211 later. Fixes: cd418ba ("mac80211: convert S1G beacon to scan results") Reported-by: syzbot+405843667e93b9790fc1@syzkaller.appspotmail.com Signed-off-by: Du Cheng <ducheng2@gmail.com> Link: https://lore.kernel.org/r/20210510041649.589754-1-ducheng2@gmail.com [style fixes, reword commit message] Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent b90f51e commit e298aa3

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

‎net/mac80211/scan.c‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,24 @@ void ieee80211_scan_rx(struct ieee80211_local *local, struct sk_buff *skb)
251251
struct ieee80211_mgmt *mgmt = (void *)skb->data;
252252
struct ieee80211_bss *bss;
253253
struct ieee80211_channel *channel;
254+
size_t min_hdr_len = offsetof(struct ieee80211_mgmt,
255+
u.probe_resp.variable);
256+
257+
if (!ieee80211_is_probe_resp(mgmt->frame_control) &&
258+
!ieee80211_is_beacon(mgmt->frame_control) &&
259+
!ieee80211_is_s1g_beacon(mgmt->frame_control))
260+
return;
254261

255262
if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
256-
if (skb->len < 15)
257-
return;
258-
} else if (skb->len < 24 ||
259-
(!ieee80211_is_probe_resp(mgmt->frame_control) &&
260-
!ieee80211_is_beacon(mgmt->frame_control)))
263+
if (ieee80211_is_s1g_short_beacon(mgmt->frame_control))
264+
min_hdr_len = offsetof(struct ieee80211_ext,
265+
u.s1g_short_beacon.variable);
266+
else
267+
min_hdr_len = offsetof(struct ieee80211_ext,
268+
u.s1g_beacon);
269+
}
270+
271+
if (skb->len < min_hdr_len)
261272
return;
262273

263274
sdata1 = rcu_dereference(local->scan_sdata);

0 commit comments

Comments
 (0)