* [PATCH] scsi: ufs: core: disable exception work before removing hwmon
@ 2026-11-26 11:14 Yaohan Li
2026-11-26 11:22 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Yaohan Li @ 2026-11-26 11:14 UTC (permalink / raw)
To: Martin K . Petersen, James E . J . Bottomley
Cc: Alim Akhtar, Bart Van Assche, Bean Huo, Stanley Jhu, linux-scsi,
linux-kernel
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@vger.kernel.org # v6.10+
Signed-off-by: Yaohan Li <shunsheng1218@gmail.com>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] scsi: ufs: core: disable exception work before removing hwmon
2026-11-26 11:14 [PATCH] scsi: ufs: core: disable exception work before removing hwmon Yaohan Li
@ 2026-11-26 11:22 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-26 11:22 UTC (permalink / raw)
To: Yaohan Li; +Cc: linux-scsi
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] scsi: ufs: core: use-after-free in
ufshcd_rpm_dev_flush_recheck_work() [1]
--
commit a1077f0758756bac493f25126be2d29218ae49d7
Author: Yaohan Li <shunsheng1218@gmail.com>
scsi: ufs: core: disable exception work before removing hwmon
This commit calls disable_work_sync(&hba->eeh_work) in ufshcd_remove()
before unregistering hwmon so that running or newly queued exception work
cannot access the freed hwmon device.
> diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> index 00a7637a1487d..f2a132c27fa0e 100644
> --- a/drivers/ufs/core/ufshcd.c
> +++ b/drivers/ufs/core/ufshcd.c
> @@ -11024,6 +11024,7 @@ void ufshcd_remove(struct ufs_hba *hba)
> {
> if (hba->ufs_device_wlun)
> ufshcd_rpm_get_sync(hba);
> + disable_work_sync(&hba->eeh_work);
[Severity: Critical]
This problem wasn't introduced by this patch, but can
ufshcd_rpm_dev_flush_recheck_work() trigger a use-after-free on hba during
ufshcd_remove() [1]?
ufshcd_rpm_get_sync() resumes the device via __ufshcd_wl_resume(), which
only calls asynchronous cancel_delayed_work() on
hba->rpm_dev_flush_recheck_work:
drivers/ufs/core/ufshcd.c:__ufshcd_wl_resume() {
...
if (hba->dev_info.b_rpm_dev_flush_capable) {
hba->dev_info.b_rpm_dev_flush_capable = false;
cancel_delayed_work(&hba->rpm_dev_flush_recheck_work);
}
...
}
Because ufshcd_remove() does not call cancel_delayed_work_sync() on
hba->rpm_dev_flush_recheck_work, an already running worker can outlive
host teardown:
CPU0 CPU1
ufshcd_remove()
ufshcd_rpm_dev_flush_recheck_work()
ufshcd_rpm_get_sync(hba)
__ufshcd_wl_resume()
cancel_delayed_work(...)
...
// hba is torn down and freed
ufshcd_rpm_put_sync(hba) <-- use-after-free
[1] https://sashiko.dev/#/bug/linux-6d2939f8-3e6b-4a28-a988-2094ecabbec6
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126111400.2828356-1-shunsheng1218@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-26 11:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 11:14 [PATCH] scsi: ufs: core: disable exception work before removing hwmon Yaohan Li
2026-11-26 11:22 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox