Skip to content

RTL8189ES: fix BSS use-after-free after a roam - #150

Open
gsustek wants to merge 1 commit into
jwrdegoede:masterfrom
gsustek:fix-sta-ch-switch-notify
Open

gsustek wants to merge 1 commit into
jwrdegoede:masterfrom
gsustek:fix-sta-ch-switch-notify

Conversation

@gsustek

@gsustek gsustek commented Nov 14, 2026

Copy link
Copy Markdown

On kernels >= 3.19, rtw_cfg80211_allow_ch_switch_notify() lets the station join path (rtw_chk_start_clnt_join()) call cfg80211_ch_switch_notify(). During a roam, cfg80211 still holds the old AP as current_bss, so cfg80211_update_assoc_bss_entry() rehashes that old entry into the BSS rbtree after the driver has already removed it with rtw_cfg80211_unlink_bss(). The entry is freed while still in the tree, and the next BSS expiry crashes:

Unable to handle kernel paging request at virtual address 006b6b6b6b6b6b7b
Comm: iw
pc : rb_erase+0x24/0x3a4
lr : __cfg80211_unlink_bss+0x7c/0x174 [cfg80211]
Call trace:
 rb_erase+0x24/0x3a4 (P)
 __cfg80211_bss_expire+0x5c/0xc0 [cfg80211]
 cfg80211_bss_expire+0x20/0x38 [cfg80211]
 nl80211_dump_scan+0x19c/0x1e0 [cfg80211]

The call also runs from the command thread without the wiphy lock that cfg80211_ch_switch_notify() requires.

Change

rtw_cfg80211_allow_ch_switch_notify() returns 0 for every interface that is not AP, ad-hoc or mesh on all kernels, as it already did before 3.19. The driver implements .connect, not .auth/.assoc, so cfg80211 takes the channel of a newly joined BSS from the connect or roam result. The other two callers (rtw_join_done_chk_ch() and start_bss_network()) notify AP-side interfaces and are unchanged.

Testing

NEXBOX A95X (Amlogic S905, RTL8189ES on SDIO), Linux 6.18.32 arm64, slub_debug=FZP:

  • Before: the box crashed four times in one day, each time after a roam. A kprobe trace showed cfg80211_update_assoc_bss_entry() and cfg80211_rehash_bss() running on the unlinked entry of the previous AP.
  • After: 20 rounds of a forced roam between two APs (wpa_supplicant Roam), each followed by a scan, iw dev wlan0 link and iw dev wlan0 scan dump. Result: 24 AP changes, no warning, no crash, and no call of cfg80211_ch_switch_notify(), cfg80211_update_assoc_bss_entry() or cfg80211_rehash_bss().

The test build was commit 36d917d plus this change. The commits on master since then add support for newer kernels and fix compiler warnings; none of them changes behavior on 6.18.

On kernels >= 3.19, rtw_cfg80211_allow_ch_switch_notify() allows a
channel switch notification for every interface type. For a station,
the only caller is the join path, rtw_chk_start_clnt_join(), which
reports the channel of the BSS that it joins.

During a roam, cfg80211 still holds the old AP as current_bss when the
join path runs. cfg80211_ch_switch_notify() then calls
cfg80211_update_assoc_bss_entry(), which moves that old entry to the
new channel and rehashes it into the BSS rbtree, although the driver
has already removed it with rtw_cfg80211_unlink_bss(). The entry is
freed while it is still in the tree, and the next BSS expiry crashes
on slab poison:

  Unable to handle kernel paging request at virtual address 006b6b6b6b6b6b7b
  Comm: iw
  pc : rb_erase+0x24/0x3a4
  lr : __cfg80211_unlink_bss+0x7c/0x174 [cfg80211]
  Call trace:
   rb_erase+0x24/0x3a4 (P)
   __cfg80211_bss_expire+0x5c/0xc0 [cfg80211]
   cfg80211_bss_expire+0x20/0x38 [cfg80211]
   nl80211_dump_scan+0x19c/0x1e0 [cfg80211]

The join path also runs from the command thread without the wiphy lock
that cfg80211_ch_switch_notify() requires.

The driver implements .connect, not .auth/.assoc, so cfg80211 takes the
channel of a newly joined BSS from the connect or roam result. The
comment at the call site about MLME frames sent by the supplicant does
not apply. Return 0 for every interface that is not AP, ad-hoc or mesh
on all kernels, as the function already did before 3.19.

Tested on a NEXBOX A95X (Amlogic S905, RTL8189ES on SDIO) with Linux
6.18.32 arm64. Before the change, the box crashed four times in one day,
each time after a roam. With the change, 20 rounds of a forced roam
between two APs, each followed by a scan, "iw dev wlan0 link" and
"iw dev wlan0 scan dump", gave 24 AP changes without a warning or a
crash, and kprobes counted no call of cfg80211_ch_switch_notify().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant