wifi: nxpwifi: fix AP channel-switch lifetime and failures
cover wifi: nxpwifi: fix AP channel-switch lifetime and failures
NXPWIFI retains request-owned beacon buffers for delayed AP channel-switch work. Once the nl80211 request is released, the IE parser can read freed memory and copy stale bytes into management-IE commands sent to firmware.
Deep-copy that beacon data, cancel pending work when the AP stops, defer blocking AP traffic until switch preparation succeeds, and stop the interface when delayed work cannot complete the switch.
The series was not run on IW61x hardware. Testing from IW61x users would be helpful. All four patches apply without changes to v7.3. Patch 3 has 144 hunk-body lines with context, above the stable tree's 100-line limit, so patches 3 and 4 need a smaller reviewed backport.
LLM assistance was used to review this series.
Zhao Li (4):
wifi: nxpwifi: cancel channel switch work on teardown
wifi: nxpwifi: stop AP TX after preparing channel switch
wifi: nxpwifi: own beacon data used by channel switch work
wifi: nxpwifi: stop AP when delayed channel switch fails
drivers/net/wireless/nxp/nxpwifi/11h.c | 22 ++++-- drivers/net/wireless/nxp/nxpwifi/cfg80211.c | 74 ++++++++++++++++++--- drivers/net/wireless/nxp/nxpwifi/main.h | 2 +- 3 files changed, 81 insertions(+), 17 deletions(-)
base-commit: 25e73f1d6868c759c8eb56cad4e411692c5341b4
Signature · 1 line
2.56.0
PATCH 1/4 wifi: nxpwifi: cancel channel switch work on teardown
Stopping an AP while channel-switch work is pending leaves the delayed work armed. After driver removal, the callback runs on freed driver state. If the AP is restarted first, the callback switches it to the old target channel. Reusing the interface slot can also reinitialize the work while it is still pending.
Cancel the work when the AP stops. Interface deletion, type changes and driver removal all stop a running AP first.
LLM assistance was used to find the bug and review.
---
Validation: A W=1 module build with MODPOST passed. Not reproduced; IW61x hardware was unavailable.
Sparse C=2 passed. Targeted Smatch introduced no new diagnostics.
drivers/net/wireless/nxp/nxpwifi/cfg80211.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/wireless/nxp/nxpwifi/cfg80211.c +1 -0
@@ -1638,6 +1638,7 @@ static int nxpwifi_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev,struct nxpwifi_private *priv =nxpwifi_netdev_get_priv (dev);int ret; +wiphy_delayed_work_cancel (wiphy, &priv->dfs_chan_sw_work);nxpwifi_abort_cac (priv);if (nxpwifi_del_mgmt_ies (priv))
Signature · 1 line
2.56.0
[email protected]
AppliedRe: [PATCH 1/4] wifi: nxpwifi: cancel channel switch work on teardown
From: Jeff Chen <[email protected]>
Quoted 10 lines · Zhao Li
Stopping an AP while channel-switch work is pending leaves the delayed work armed. After driver removal, the callback runs on freed driver state. If the AP is restarted first, the callback switches it to the old target channel. Reusing the interface slot can also reinitialize the work while it is still pending.
Cancel the work when the AP stops. Interface deletion, type changes and driver removal all stop a running AP first.
LLM assistance was used to find the bug and review.
Applied, thanks.
For future submissions, please consider keeping the changelog more concise and focused on the bug and fix. The discussion of possible consequences feels longer than necessary for a patch of this size.
Also, there's probably no need to mention LLM assistance in the changelog.
PATCH 2/4 wifi: nxpwifi: stop AP TX after preparing channel switch
In reply to Zhao LiA channel-switch request can leave AP traffic stopped if installing the CSA management IEs fails or the driver's work wrapper refuses the request. The driver disables carrier and the TX queues before programming the IEs, and the wrapper silently drops work during removal, command timeout or suspend.
Prepare the CSA IEs before stopping traffic. Queue the switch directly with wiphy_delayed_work_queue(), since the driver's wrapper can silently discard it after the IEs are installed and traffic is stopped. The wiphy mutex serializes the callback and worker with AP-stop cancellation.
LLM assistance was used to find the bug and review.
---
Validation: A W=1 module build with MODPOST passed. Not reproduced; IW61x hardware was unavailable.
Sparse C=2 passed. Targeted Smatch introduced no new diagnostics.
drivers/net/wireless/nxp/nxpwifi/cfg80211.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/net/wireless/nxp/nxpwifi/cfg80211.c +8 -9
@@ -3115,12 +3115,6 @@ nxpwifi_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, &priv->dfs_chandef))return -EINVAL ; -if (params->block_tx) { -netif_carrier_off (priv->netdev); -nxpwifi_stop_net_dev_queue (priv->netdev, priv->adapter); - priv->uap_stop_tx = true; - } - ret =nxpwifi_del_mgmt_ies (priv);if (ret) nxpwifi_dbg(priv->adapter, ERROR,
@@ -3137,11 +3131,16 @@ nxpwifi_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,memcpy (&priv->ap_update_info.beacon, ¶ms->beacon_after,sizeof (priv->ap_update_info.beacon)); +if (params->block_tx) { +netif_carrier_off (priv->netdev); +nxpwifi_stop_net_dev_queue (priv->netdev, priv->adapter); + priv->uap_stop_tx = true; + } + chsw_msec =max (params->count * priv->bss_cfg.beacon_period,100 ); -nxpwifi_queue_delayed_wiphy_work (priv->adapter, - &priv->dfs_chan_sw_work, -msecs_to_jiffies (chsw_msec)); +wiphy_delayed_work_queue (wiphy, &priv->dfs_chan_sw_work, +msecs_to_jiffies (chsw_msec)); done:return ret;
Signature · 1 line
2.56.0
Re: [PATCH 2/4] wifi: nxpwifi: stop AP TX after preparing channel switch
From: Jeff Chen <[email protected]>
drivers/net/wireless/nxp/nxpwifi/cfg80211.c nxpwifi_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, · line 3143
Quoted 5 lines · Zhao Li
drivers/net/wireless/nxp/nxpwifi/cfg80211.c +2
-3-nxpwifi_queue_delayed_wiphy_work (priv->adapter, - &priv->dfs_chan_sw_work, -msecs_to_jiffies (chsw_msec)); +wiphy_delayed_work_queue (wiphy, &priv->dfs_chan_sw_work, +msecs_to_jiffies (chsw_msec));
Hi Zhao,
Thanks for the patch.
I don't think the switch from nxpwifi_queue_delayed_wiphy_work() to wiphy_delayed_work_queue() is related to the issue being fixed here.
The wrapper only drops work when SURPRISE_REMOVED, IS_CMD_TIMEDOUT, or IS_SUSPENDED is set. In those states, the preceding management IE commands already fail, so channel_switch() exits before reaching the queue call.
Also, nxpwifi_dfs_chan_sw_work() itself sends several FW commands. Even if the work is queued, those commands cannot succeed while these flags are set, so bypassing the wrapper does not appear to improve the situation.
Thanks,
Jeff
PATCH 3/4 wifi: nxpwifi: own beacon data used by channel switch work
In reply to Zhao LiChannel-switch work passes beacon data to nxpwifi_set_mgmt_ies() after the cfg80211 callback returns, but the driver retains only a shallow copy of pointers into the request. The request storage can be freed before the delayed work runs.
The IE parser can then read freed memory. Stale bytes that pass its element checks can be copied into management-IE commands sent to firmware.
Deep-copy the four beacon buffers consumed by nxpwifi_set_mgmt_ies() into an owned cfg80211_ap_update. Keep the existing change_beacon path, reject overlapping switches while the update is owned, and release it when the work finishes or is canceled.
LLM assistance was used to find the bug and review.
---
Validation: A W=1 module build with MODPOST passed. Not reproduced; IW61x hardware was unavailable.
Sparse C=2 passed. Targeted Smatch introduced no new diagnostics. All four patches apply without changes to v7.3.
This 144-line hunk-body diff exceeds the stable tree's 100-line limit, so a smaller reviewed backport is needed.
drivers/net/wireless/nxp/nxpwifi/11h.c | 14 +++-- drivers/net/wireless/nxp/nxpwifi/cfg80211.c | 58 ++++++++++++++++++++- drivers/net/wireless/nxp/nxpwifi/main.h | 2 +- 3 files changed, 66 insertions(+), 8 deletions(-)
drivers/net/wireless/nxp/nxpwifi/11h.c +9 -5
@@ -301,21 +301,21 @@ void nxpwifi_dfs_chan_sw_work(struct wiphy *wiphy, struct wiphy_work *work)if (!bss_cfg->beacon_period) {nxpwifi_dbg (adapter,ERROR ,"channel switch: AP already stopped\n" ); -return ; + goto out; }if (nxpwifi_send_cmd (priv,HOST_CMD_UAP_BSS_STOP ,HOST_ACT_GEN_SET ,0 ,NULL , true)) {nxpwifi_dbg (adapter,ERROR ,"channel switch: Failed to stop the BSS\n" ); -return ; + goto out; }if (nxpwifi_cfg80211_change_beacon (adapter->wiphy, priv->netdev, - &priv->ap_update_info)) { + priv->ap_update_info)) {nxpwifi_dbg (adapter,ERROR ,"channel switch: Failed to set beacon\n" ); -return ; + goto out; }nxpwifi_uap_set_channel (priv, bss_cfg, priv->dfs_chandef);
@@ -323,7 +323,7 @@ void nxpwifi_dfs_chan_sw_work(struct wiphy *wiphy, struct wiphy_work *work)if (nxpwifi_config_start_uap (priv, bss_cfg)) {nxpwifi_dbg (adapter,ERROR ,"Failed to start AP after channel switch\n" ); -return ; + goto out; } nxpwifi_dbg(adapter, MSG,
@@ -336,4 +336,8 @@ void nxpwifi_dfs_chan_sw_work(struct wiphy *wiphy, struct wiphy_work *work)nxpwifi_wake_up_net_dev_queue (priv->netdev, adapter); priv->uap_stop_tx = false; } + +out: +kfree (priv->ap_update_info); + priv->ap_update_info =NULL ; }
drivers/net/wireless/nxp/nxpwifi/cfg80211.c +56 -2
95 lines not on this page · raw message
drivers/net/wireless/nxp/nxpwifi/main.h +1 -1
@@ -619,7 +619,7 @@ struct nxpwifi_private {struct wiphy_delayed_work dfs_cac_work;struct wiphy_delayed_work dfs_chan_sw_work;bool uap_stop_tx; -struct cfg80211_ap_update ap_update_info; +struct cfg80211_ap_update *ap_update_info;struct nxpwifi_11h_intf_state state_11h;struct nxpwifi_ds_mem_rw mem_rw;struct sk_buff_head bypass_txq;
Signature · 1 line
2.56.0
PATCH 4/4 wifi: nxpwifi: stop AP when delayed channel switch fails
In reply to Zhao LiA delayed AP channel switch can fail while stopping the BSS, programming the new beacon, or restarting the AP. The worker returns without notifying cfg80211, and traffic can remain enabled over a stopped BSS when the request did not set block_tx.
An earlier stop failure can also clear the driver's AP configuration while cfg80211 still considers the AP running. A following channel switch then reaches the worker without a beacon period and is discarded.
Disable carrier and the TX queues, retain the channel-switch state, and request interface shutdown on all four failures. Keeping the state until the stop path cancels it prevents another switch from starting while shutdown is pending.
LLM assistance was used to find the bug and review.
---
Validation: A W=1 module build with MODPOST passed. Not reproduced; IW61x hardware was unavailable.
Sparse C=2 passed. Targeted Smatch introduced no new diagnostics. All four patches apply without changes to v7.3.
Stable pickup is disabled because this patch depends on that backport. Persistent firmware-command failure recovery was not exercised. The patch disables TX and requests interface shutdown; it does not prove that cfg80211 and firmware state converge if stop_ap() also fails.
drivers/net/wireless/nxp/nxpwifi/11h.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/net/wireless/nxp/nxpwifi/11h.c +12 -6
@@ -300,22 +300,22 @@ void nxpwifi_dfs_chan_sw_work(struct wiphy *wiphy, struct wiphy_work *work) bss_cfg = &priv->bss_cfg;if (!bss_cfg->beacon_period) {nxpwifi_dbg (adapter,ERROR , -"channel switch: AP already stopped\n" ); - goto out; +"channel switch: AP configuration is missing\n" ); + goto stop_iface; }if (nxpwifi_send_cmd (priv,HOST_CMD_UAP_BSS_STOP ,HOST_ACT_GEN_SET ,0 ,NULL , true)) {nxpwifi_dbg (adapter,ERROR ,"channel switch: Failed to stop the BSS\n" ); - goto out; + goto stop_iface; }if (nxpwifi_cfg80211_change_beacon (adapter->wiphy, priv->netdev, priv->ap_update_info)) {nxpwifi_dbg (adapter,ERROR ,"channel switch: Failed to set beacon\n" ); - goto out; + goto stop_iface; }nxpwifi_uap_set_channel (priv, bss_cfg, priv->dfs_chandef);
@@ -323,7 +323,7 @@ void nxpwifi_dfs_chan_sw_work(struct wiphy *wiphy, struct wiphy_work *work)if (nxpwifi_config_start_uap (priv, bss_cfg)) {nxpwifi_dbg (adapter,ERROR ,"Failed to start AP after channel switch\n" ); - goto out; + goto stop_iface; } nxpwifi_dbg(adapter, MSG,
@@ -337,7 +337,13 @@ void nxpwifi_dfs_chan_sw_work(struct wiphy *wiphy, struct wiphy_work *work) priv->uap_stop_tx = false; } -out:kfree (priv->ap_update_info); priv->ap_update_info =NULL ; +return ; + +stop_iface: +netif_carrier_off (priv->netdev); +nxpwifi_stop_net_dev_queue (priv->netdev, adapter); + priv->uap_stop_tx = true; +cfg80211_stop_iface (wiphy, &priv->wdev,GFP_KERNEL ); }
Signature · 1 line
2.56.0
From: Jeff Chen <[email protected]>
Quoted 3 lines · Zhao Li
NXPWIFI retains request-owned beacon buffers for delayed AP channel-switch work. Once the nl80211 request is released, the IE parser can read freed memory and copy stale bytes into management-IE commands sent to firmware.
Hi Zhao,
Thanks for the series.
Patches 1, 2 and 4 look good to me. However, patch 3 still needs to be updated based on the review comments.
While respinning the series, please also simplify the commit messages. Several of them are unnecessarily verbose and would be easier to review if they focused on the specific bug and the corresponding fix.
Please resend the updated series.
Thanks,
Jeff