[PATCH] wifi: mwifiex: fix NULL RX URB deref in firmware init error path
From: YuanZhe Liu
Date: Fri Dec 04 2026 - 11:19:43 EST
When a command sent during mwifiex_init_fw() fails, the command response
handler recycles the command node. mwifiex_insert_cmd_to_free_q() wakes
the thread waiting in mwifiex_send_cmd() before mwifiex_clean_cmd_node()
invokes the cmdrsp_complete() callback.
The woken firmware callback thread returns an error from mwifiex_init_fw()
and takes the error path in _mwifiex_fw_dpc(). That path calls
if_ops->unregister_dev() before set_bit(MWIFIEX_SURPRISE_REMOVED) and
mwifiex_terminate_workqueue(). For USB, mwifiex_unregister_dev() calls
mwifiex_usb_free(), which frees card->rx_cmd.urb and sets it to NULL.
If the main workqueue thread has not yet reached mwifiex_clean_cmd_node(),
the subsequent cmdrsp_complete() callback,
mwifiex_usb_cmd_event_complete(), resubmits the command RX URB. Since
rx_cmd_urb_pending is already zero and the URB context still has a valid
skb, mwifiex_usb_submit_rx_urb() calls usb_fill_bulk_urb() with a NULL urb
and dereferences urb->dev, producing a general protection fault in the
workqueue.
Restore the teardown order used by mwifiex_uninit_sw(): stop the workqueues
before unregistering the device so that no command response can resubmit
the RX URB after mwifiex_usb_free() has run. Move the shutdown and command
buffer cleanup ahead of unregister_dev() as well, because
mwifiex_shutdown_drv() can recycle a pending command and invoke the same
completion callback.
The failure was observed when the firmware returned an error for an
initialization command during probe. This change is compile-tested only;
the race window was not reproduced on demand.
Fixes: f8c095f67962 ("mwifiex: handle race during mwifiex_usb_disconnect")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: YuanZhe Liu <25031212351@xxxxxxxxxxxxxxxxx>
---
drivers/net/wireless/marvell/mwifiex/main.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/net/wireless/marvell/mwifiex/main.c b/drivers/net/wireless/marvell/mwifiex/main.c
index c8df3edff675..3f177aa041ae 100644
--- a/drivers/net/wireless/marvell/mwifiex/main.c
+++ b/drivers/net/wireless/marvell/mwifiex/main.c
@@ -655,11 +655,6 @@ static int _mwifiex_fw_dpc(const struct firmware *firmware, void *context)
if (adapter->if_ops.disable_int)
adapter->if_ops.disable_int(adapter);
err_dnld_fw:
- mwifiex_dbg(adapter, ERROR,
- "info: %s: unregister device\n", __func__);
- if (adapter->if_ops.unregister_dev)
- adapter->if_ops.unregister_dev(adapter);
-
set_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags);
mwifiex_terminate_workqueue(adapter);
@@ -669,6 +664,11 @@ static int _mwifiex_fw_dpc(const struct firmware *firmware, void *context)
mwifiex_free_cmd_buffers(adapter);
}
+ mwifiex_dbg(adapter, ERROR,
+ "info: %s: unregister device\n", __func__);
+ if (adapter->if_ops.unregister_dev)
+ adapter->if_ops.unregister_dev(adapter);
+
init_failed = true;
done:
if (adapter->firmware) {
--
2.34.1