Skip to content

mwifiex: pcie: cancel card work before clearing card->adapter - #189

Open
tfranssen wants to merge 1 commit into
linux-surface:v7.3-surface-develfrom
tfranssen:mwifiex-shutdown-null-fix
Open

tfranssen wants to merge 1 commit into
linux-surface:v7.3-surface-develfrom
tfranssen:mwifiex-shutdown-null-fix

Conversation

@tfranssen

Copy link
Copy Markdown

Problem

During system shutdown (mwifiex_pcie_shutdown() -> mwifiex_pcie_remove() -> mwifiex_remove_card()), mwifiex_unregister_dev() sets card->adapter = NULL before mwifiex_free_adapter() -> mwifiex_cleanup_pcie() calls cancel_work_sync(&card->work).

If mwifiex_pcie_work() is running or scheduled during shutdown or removal (e.g. triggered by a command timeout or firmware dump on Marvell 88W8897 devices such as Surface Pro 6, Surface Book 1/2, or Surface 3 as also seen in linux-surface/linux-surface#1965), mwifiex_pcie_work() passes card->adapter (NULL) to mwifiex_pcie_device_dump_work() / mwifiex_pcie_card_reset_work(), resulting in a kernel NULL pointer dereference Oops during poweroff:

Requesting system poweroff
BUG: kernel NULL pointer dereference, address: 00000000000000a0
Workqueue: events mwifiex_pcie_work [mwifiex_pcie]
RIP: 0010:mwifiex_pcie_work+0x324/0x440 [mwifiex_pcie]

Fix

  1. Call cancel_work_sync(&card->work) (when !card->pci_reset_ongoing) in mwifiex_unregister_dev() after freeing IRQs and before clearing card->adapter = NULL.
  2. Add a defensive if (!card->adapter) return; check in mwifiex_pcie_work().

Made with Cursor

In mwifiex_remove_card(), mwifiex_unregister_dev() sets card->adapter = NULL
before mwifiex_free_adapter() -> mwifiex_cleanup_pcie() calls
cancel_work_sync(&card->work). If mwifiex_pcie_work() is scheduled during
shutdown or removal, it dereferences NULL card->adapter (at offset 0x88/0xa0),
causing a kernel NULL pointer dereference Oops during system poweroff.

Cancel card->work before setting card->adapter = NULL in
mwifiex_unregister_dev(), and guard against a NULL card->adapter in
mwifiex_pcie_work().

Patchset: mwifiex
Signed-off-by: Thijs Franssen <54217714+tfranssen@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
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