Hi Johannes,
While testing v7.4-rc3 with an LLM-guided test generator that we are
developing as a research prototype, we found that when a station
follows a channel switch to a channel where its AP already has a hidden
SSID group in the scan list, cfg80211_update_assoc_bss_entry() warns:
WARNING: net/wireless/scan.c:3537 at cfg80211_update_assoc_bss_entry+0x53a/0x7c0, CPU#0: kworker/u8:2/44
Workqueue: events_unbound cfg80211_wiphy_work
RIP: 0010:cfg80211_update_assoc_bss_entry (net/wireless/scan.c:3537)
Call Trace:
cfg80211_ch_switch_notify (net/wireless/nl80211.c:23295)
ieee80211_sta_process_chanswitch (net/mac80211/mlme.c:3328)
ieee80211_rx_mgmt_beacon (net/mac80211/mlme.c:8381)
ieee80211_sta_rx_queued_frame (net/mac80211/mlme.c:11909)
ieee80211_iface_work (net/mac80211/iface.c:1805 net/mac80211/iface.c:1862)
cfg80211_wiphy_work (net/wireless/core.c:609)
process_one_work (kernel/workqueue.c:3495)
worker_thread (kernel/workqueue.c:3578 kernel/workqueue.c:3659)
kthread (kernel/kthread.c:436)
ret_from_fork (arch/x86/kernel/process.c:158)
ret_from_fork_asm (arch/x86/entry/entry_64.S:245)
and a later scan dump can read the group's beacon IEs after they were
freed:
BUG: KASAN: slab-use-after-free in nl80211_send_bss.constprop.0 (net/wireless/nl80211.c:12959)
Read of size 1 at addr ff1100001428e61c by task test/115
Call Trace:
nl80211_send_bss.constprop.0 (net/wireless/nl80211.c:12959)
nl80211_dump_scan (net/wireless/nl80211.c:13105)
genl_dumpit (net/netlink/genetlink.c:1026)
netlink_dump (net/netlink/af_netlink.c:2360)
__netlink_dump_start (net/netlink/af_netlink.c:2475)
genl_family_rcv_msg_dumpit (net/netlink/genetlink.c:1075)
genl_rcv_msg (net/netlink/genetlink.c:1191 net/netlink/genetlink.c:1209)
netlink_rcv_skb (net/netlink/af_netlink.c:2585)
genl_rcv (net/netlink/genetlink.c:1218)
netlink_unicast (net/netlink/af_netlink.c:1336 net/netlink/af_netlink.c:1362)
netlink_sendmsg (net/netlink/af_netlink.c:1921)
__sys_sendto (net/socket.c:2283)
do_syscall_64 (arch/x86/entry/syscall_64.c:61 arch/x86/entry/syscall_64.c:89)
entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
The entry on the new channel that matches the associated BSS gives its
IEs to cbss and is then unlinked:
if (new) {
/* to save time, update IEs for transmitting bss only */
cfg80211_update_known_bss(rdev, cbss, new, false);
new->pub.proberesp_ies = NULL;
new->pub.beacon_ies = NULL;
...
WARN_ON(atomic_read(&new->hold));
if (!WARN_ON(!__cfg80211_unlink_bss(rdev, new)))
rdev->bss_generation++;
}
When new is the beacon entry of a hidden SSID group,
__cfg80211_unlink_bss() refuses to remove it while the group has probe
response entries. new stays on the list, so cfg80211_rehash_bss() of
cbss also warns in rb_insert_bss(), and the probe response entries
still share the beacon IEs that cfg80211_update_known_bss() just gave
to cbss. Once cbss is freed, bss_free() frees those IEs, and the next
GET_SCAN dump reads them through a probe response entry.
cc45f313d855 ("wifi: cfg80211: preserve hidden-group beacon IE
ownership") covers the case where new is a member of such a group; this
is the case where new is the group's beacon entry.
The reproducer runs as root and drives two mac80211_hwsim radios over
nl80211: an AP interface sends hidden SSID beacons and probe responses
on channel 1 while the station scans, the station associates with the
same AP on channel 6, and the AP announces a channel switch to channel
1. The WARN fires on every run. The use-after-free also needs the
station to disconnect, a flush scan that expires the old entry and a
GET_SCAN dump, and shows up in some runs.
Checked against v7.4-rc3 (aebb72744764); the code is the same in the
wireless tree and in wireless-next.
A fix follows as a reply. The reproducer (repro.c) and the kernel
config are attached.
Thanks,
Kyuwon Cho