]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
mmc: vub300: defer reset until cmd_mutex is unlocked
authorRunyu Xiao <runyu.xiao@seu.edu.cn>
Wed, 17 Jun 2026 15:23:19 +0000 (23:23 +0800)
committerUlf Hansson <ulfh@kernel.org>
Mon, 6 Jul 2026 14:20:12 +0000 (16:20 +0200)
commitee5fb641c4ccac8406c668d3e947eb20ce44f233
tree5b7eb58919c1ea05482c4e7bb7c65ef2f13807fd
parenta3b5f242997a3be7404112fd48784881560aea57
mmc: vub300: defer reset until cmd_mutex is unlocked

vub300_cmndwork_thread() holds cmd_mutex while it sends a command and
waits for the command response.  If the response wait times out,
__vub300_command_response() kills the command URBs and then synchronously
resets the USB device through usb_reset_device().

That reset path re-enters the driver through vub300_pre_reset(), which
also takes cmd_mutex.  The worker therefore tries to acquire the same
mutex recursively while it is still holding it from the command path.

This issue was found by our static analysis tool and then manually
reviewed against the current tree.

The grounded PoC kept the real worker and timeout/reset carrier:

  vub300_cmndwork_thread()
  __vub300_command_response()
  usb_lock_device_for_reset()
  usb_reset_device()
  vub300_pre_reset()

Lockdep reported the same-task recursive acquisition on cmd_mutex:

  WARNING: possible recursive locking detected
  ... (&test_vub300.cmd_mutex) ... at: usb_reset_device... [vuln_msv]
  ... (&test_vub300.cmd_mutex) ... at: vub300_cmndwork_thread+0x12/0x20 [vuln_msv]
  Workqueue: vub300_cmd_wq vub300_cmndwork_thread [vuln_msv]
  *** DEADLOCK ***

Return a flag from __vub300_command_response() when the timeout path needs
a device reset, then perform the reset after vub300_cmndwork_thread() has
cleared the in-flight command state and dropped cmd_mutex.  The reset is
still attempted before mmc_request_done(), preserving the existing request
completion ordering while avoiding the recursive lock.

Fixes: 88095e7b473a ("mmc: Add new VUB300 USB-to-SD/SDIO/MMC driver")
Cc: stable@vger.kernel.org
Signed-off-by: Runyu Xiao <runyu.xiao@seu.edu.cn>
Signed-off-by: Ulf Hansson <ulfh@kernel.org>
drivers/mmc/host/vub300.c