mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] scsi: ufs: core: disable exception work before removing hwmon
@ 2026-11-26 11:14 Yaohan Li
  2026-11-26 18:09 ` Bean Huo
  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	[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 18:09 ` Bean Huo
  0 siblings, 0 replies; 2+ messages in thread
From: Bean Huo @ 2026-11-26 18:09 UTC (permalink / raw)
  To: Yaohan Li, Martin K . Petersen, James E . J . Bottomley
  Cc: Alim Akhtar, Bart Van Assche, Bean Huo, Stanley Jhu, linux-scsi,
	linux-kernel

On Thu, 2026-11-26 at 19:14 +0800, Yaohan Li wrote:
> 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")

please double check this fix tag, should be  e88e2d32200a, where hwmon came in?

Kind regards,
Bean

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-26 18:09 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 18:09 ` Bean Huo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®