wifi: mac80211: fix use-after-free when MLO link setup is rolled back
Subsystems (2)
PATCH 1/1 wifi: mac80211: fix use-after-free when MLO link setup is rolled back
Rolling back an MLO link addition can free link containers while RCU readers still hold pointers to them. ieee80211_vif_update_links() publishes new links before checking for duplicate addresses and calling drv_change_vif_links(). If either fails, it restores the old pointers and frees the new containers without waiting for readers.
During a non-MLO to MLO transition, the published link 0 replaces the deflink, so existing link 0 users can acquire the new container. Readers such as ieee80211_csa_finish() and ieee80211_obss_color_collision_notify() can also queue work embedded in the link. If they queue after ieee80211_link_stop() cancels that work, it remains queued when the container is freed.
Wait for RCU readers after restoring the old pointers and before stopping the new links, so their work is queued before it is cancelled.
---
LLM-assisted source review and patch preparation.
KASAN test-tree harness: pre-fix 22 reports, fixed 0; wait after stop 22. Sparse, Smatch and driver-failure testing were not run.
Older affected kernels need an adapted rollback hunk.
net/mac80211/link.c | 2 ++ 1 file changed, 2 insertions(+)
net/mac80211/link.c +2 -0
@@ -401,6 +401,8 @@ static int ieee80211_vif_update_links(struct ieee80211_sub_if_data *sdata,memcpy (sdata->link, old_data,sizeof (old_data));memcpy (sdata->vif.link_conf, old,sizeof (old));ieee80211_set_vif_links_bitmaps (sdata, old_links, dormant_links); +/* drain RCU readers before cancelling work they may queue */ +synchronize_rcu ();for_each_set_bit (link_id, &add,IEEE80211_MLD_MAX_NUM_LINKS ) {ieee80211_link_debugfs_remove (&links[link_id]->data);ieee80211_link_stop (&links[link_id]->data);
base-commit: 6b4b543fa18757297ac756a6fe6e64f506b7844a
Signature · 1 line
2.56.0
PATCH 1/1 wifi: mac80211: restore dormant links when link updates fail
A failed MLO link update can leave the interface with the requested dormant-links bitmap instead of its previous one. This can disable active links or trigger a bitmap warning during rollback.
The error path restores the old valid-links bitmap but passes the new dormant_links argument to ieee80211_set_vif_links_bitmaps().
Save the old dormant bitmap before changing link state and use it when restoring the old configuration.
LLM assistance was used to find the bug and review.
---
Validation: A W=1 module build with MODPOST passed on top of the prerequisite patch. A QEMU guest forced duplicate-address rollback: the old code cleared dormant and active links, while this change preserved dormant=0x2 and active=0x1 without a warning. The driver-failure path was not run. A reproducer is available on request.
Sparse C=2 passed. Targeted Smatch introduced no new diagnostics.
Depends on "wifi: mac80211: fix use-after-free when MLO link setup is rolled back", Message-ID <[email protected]>.
net/mac80211/link.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/mac80211/link.c +2 -1
@@ -290,6 +290,7 @@ static int ieee80211_vif_update_links(struct ieee80211_sub_if_data *sdata, {u16 old_links = sdata->vif.valid_links;u16 old_active = sdata->vif.active_links; +u16 old_dormant = sdata->vif.dormant_links;unsigned long add = new_links & ~old_links;unsigned long rem = old_links & ~new_links;unsigned long sta_rem = rem;
@@ -399,7 +400,7 @@ static int ieee80211_vif_update_links(struct ieee80211_sub_if_data *sdata,/* restore config */ memcpy (sdata->link, old_data,sizeof (old_data));memcpy (sdata->vif.link_conf, old,sizeof (old)); -ieee80211_set_vif_links_bitmaps (sdata, old_links, dormant_links); +ieee80211_set_vif_links_bitmaps (sdata, old_links, old_dormant);/* drain RCU readers before cancelling work they may queue */ synchronize_rcu ();for_each_set_bit (link_id, &add,IEEE80211_MLD_MAX_NUM_LINKS ) {
base-commit: 25e73f1d6868c759c8eb56cad4e411692c5341b4
prerequisite-patch-id: f3df0cde74cce63ac37decd81c2613cdb13f49ff
Signature · 1 line
2.56.0