[PATCH] scsi: ufs: core: disable exception work before removing hwmon

From: Yaohan Li

Date: Thu Nov 26 2026 - 06:14:14 EST


ufshcd_remove() unregisters the hwmon device while hba->eeh_work can
still be running. A SCSI completion can also queue hba->eeh_work later
during scsi_remove_host(). When the worker runs ufs_hwmon_notify_event(),
it can access the freed hwmon device and trigger a use-after-free.

Disable and drain hba->eeh_work in ufshcd_remove() before removing
hwmon. This ensures any running handler finishes while hwmon is still
present and prevents later SCSI completions during removal from
requeuing the work.

Fixes: 66ec6d59407b ("[SCSI] ufs: Add support for host assisted background operations")
Cc: stable@xxxxxxxxxxxxxxx # v6.10+
Signed-off-by: Yaohan Li <shunsheng1218@xxxxxxxxx>
---
Tested in QEMU/KVM (KASAN + PROVE_LOCKING) with an out-of-tree virtual
UFS 3.1 platform controller driving the in-tree ufshcd-core.ko (no
kprobes):
- Unbinding the device during an exception-event alert flood hits a
KASAN slab-use-after-free in hwmon_notify_event() /
kobject_uevent_env() from ufshcd_exception_event_handler() (freed by
ufs_hwmon_remove() <- ufshcd_remove()) on the unpatched kernel, and
passes 10-cycle A/B and 30-cycle stress runs with no KASAN, warning,
or lockdep reports after the patch.
- Exception alerts on SYNCHRONIZE_CACHE during scsi_remove_host()
requeue eeh_work on 10/10 cycles before the patch and 0/10 cycles
after.
- Compile-tested with W=1 on x86_64 and arm64; verified clean apply on
mkp/scsi.git for-next.
- Not tested on physical UFS hardware.

AI assistance: AI tools assisted with static code triage, writing the
virtual UFS QEMU test module, and drafting the changelog; I reviewed and
verified the root cause, teardown order, workqueue/lock behavior, and
the final patch.

drivers/ufs/core/ufshcd.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 3c28bc67c65f..86100ac90fce 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -10988,6 +10988,7 @@ void ufshcd_remove(struct ufs_hba *hba)
{
if (hba->ufs_device_wlun)
ufshcd_rpm_get_sync(hba);
+ disable_work_sync(&hba->eeh_work);
ufs_hwmon_remove(hba);
ufs_bsg_remove(hba);
ufs_rpmb_remove(hba);
--
2.34.1