wifi: mwifiex: serialize synchronous command buffer access
Subsystems (2)
PATCH 1/1 wifi: mwifiex: serialize synchronous command buffer access
Commit ef06882c7d8a ("wifi: mwifiex: Detach sync cmd buffer on interrupted wait") clears a synchronous command data_buf after an interrupted or timed-out wait. The response side does not hold mwifiex_cmd_lock while using that pointer, however. It can cache data_buf before the clear, then write to the caller stack after the waiter returns. If the clear wins, three response handlers instead dereference NULL.
The normal cfg80211 path is affected. An unprivileged NL80211_CMD_GET_INTERFACE request on a connected HT interface reaches get_channel, which passes a stack channel_band to a synchronous STA_CONFIGURE command. Its response writes through data_buf. Raw host commands have the same check/use window.
Move the detach into mwifiex_cancel_all_pending_cmd() while mwifiex_cmd_lock is held and before completing the command. Dispatch only the short, non-sleeping response handlers that copy to data_buf under the same lock through their final write. Protect the VERSION_EXT copy separately because its other branch queues a command. Serialize the raw host-command copy as well, and let the three unconditional handlers discard a detached buffer.
If cancellation wins the lock, a later response observes NULL. If the response wins it, cancellation cannot wake the buffer owner until copyout has completed.
Compile-tested with LLVM 22.1.8 and W=1. Runtime testing was not possible because no supported mwifiex hardware was available.
--- drivers/net/wireless/marvell/mwifiex/cmdevt.c | 8 ++ .../wireless/marvell/mwifiex/sta_cmdresp.c | 119 ++++++++++++------ .../net/wireless/marvell/mwifiex/sta_ioctl.c | 12 -- 3 files changed, 89 insertions(+), 50 deletions(-)
drivers/net/wireless/marvell/mwifiex/cmdevt.c +8 -0
@@ -838,11 +838,14 @@ int mwifiex_process_cmdresp(struct mwifiex_adapter *adapter)mwifiex_dbg (adapter,INFO ,"info: host cmd resp size = %d\n" , size); size =min_t (u16, size,MWIFIEX_SIZE_OF_CMD_BUFFER ); +/* Serialize against cancellation of the caller-owned buffer. */ +spin_lock_bh (&adapter->mwifiex_cmd_lock);if (adapter->curr_cmd->data_buf) { hostcmd = adapter->curr_cmd->data_buf; hostcmd->len = size;memcpy (hostcmd->cmd, resp, size); } +spin_unlock_bh (&adapter->mwifiex_cmd_lock); }/* Get BSS number and corresponding priv */
@@ -1050,6 +1053,8 @@ mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter *adapter)spin_lock_bh (&adapter->mwifiex_cmd_lock);/* Cancel current cmd */ if ((adapter->curr_cmd) && (adapter->curr_cmd->wait_q_enabled)) { +/* Do not wake the owner while a response can still use its data. */ + adapter->curr_cmd->data_buf =NULL ; adapter->cmd_wait_q.status =-1 ;mwifiex_complete_cmd (adapter, adapter->curr_cmd); adapter->curr_cmd->wait_q_enabled = false;
@@ -1702,6 +1707,9 @@ int mwifiex_ret_wakeup_reason(struct mwifiex_private *priv, struct host_cmd_ds_command *resp, struct host_cmd_ds_wakeup_reason *wakeup_reason) { +if (!wakeup_reason) +return 0 ; + wakeup_reason->wakeup_reason = resp->params.hs_wakeup_reason.wakeup_reason;
drivers/net/wireless/marvell/mwifiex/sta_cmdresp.c +81 -38
214 lines not on this page · raw message
drivers/net/wireless/marvell/mwifiex/sta_ioctl.c +0 -12
@@ -57,18 +57,6 @@ int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter,mwifiex_dbg (adapter,ERROR ,"cmd_wait_q terminated: %d\n" , status);mwifiex_cancel_all_pending_cmd (adapter); - -/* The command response path writes through cmd_node->data_buf. -* On an interrupted wait, the caller can return and release a -* stack-allocated data_buf before a late firmware response is -* processed. Detach the caller-owned buffer from the current -* command so a late response cannot corrupt freed stack memory. -*/ -spin_lock_bh (&adapter->mwifiex_cmd_lock); -if (adapter->curr_cmd == cmd_queued) - adapter->curr_cmd->data_buf =NULL ; -spin_unlock_bh (&adapter->mwifiex_cmd_lock); -return status; }
Signature · 1 line
2.43.0
Francesco Dolcini
reviewerOn Tue, Oct 27, 2026 at 06:57:07AM +0000, Jaeyeong Lee wrote:
[...]
Quoted 2 lines
Compile-tested with LLVM 22.1.8 and W=1. Runtime testing was not possible because no supported mwifiex hardware was available.
What's the point of such a patch you did not even test? No, thanks?
Francesco