Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme-multipath: delete the ANATT timer after draining ana_work
@ 2026-11-24 12:13 Guixin Liu
  2026-11-24 12:22 ` sashiko-bot
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Guixin Liu @ 2026-11-24 12:13 UTC (permalink / raw)
  To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
	Nilay Shroff, Daniel Wagner, Hannes Reinecke
  Cc: linux-nvme

nvme_mpath_stop() deletes the ANATT timer before cancelling ana_work.
An ana_work that is already past its controller state check can still
read the ANA log and arm the timer after the timer was deleted. The
controller is then freed with the timer armed, and nvme_anatt_timeout()
dereferences the freed controller when it fires.

Cancel ana_work before deleting the timer so it cannot be armed again.
Also delete the timer in nvme_mpath_uninit() after draining ana_work:
commit 9b657c565984 ("nvme: stop asynchronous event work before ANA
teardown") added the work drain there because ana_work has multiple
producers and nvme_mpath_stop() is skipped once ana_log_buf is NULL.
The timer needs the same treatment before the ANA resources are freed.

Fixes: 0d0b660f214d ("nvme: add ANA support")
Cc: stable@vger.kernel.org
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
Found by code inspection; reproduced in a KASAN guest with nvmet-tcp
loopback, two paths and an ANA group in change state. With a test-only
delay widening the ana_work window, deleting the controller while
ana_work is in flight arms the timer after nvme_mpath_stop() deleted
it, and twenty seconds after the controller is freed:

  BUG: KASAN: slab-use-after-free in __run_timers+0x887/0x990
  Write of size 8 at addr ffff8884ec888e00 by task swapper/24/0

With the fix the same recipe completes with no splat and both
controllers are removed cleanly. ANA change/optimized transitions and
multipath I/O were verified unaffected.

 drivers/nvme/host/multipath.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index 3685c792181b..bd27a5355bab 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -1074,8 +1074,8 @@ void nvme_mpath_stop(struct nvme_ctrl *ctrl)
 {
 	if (!nvme_ctrl_use_ana(ctrl))
 		return;
-	timer_delete_sync(&ctrl->anatt_timer);
 	cancel_work_sync(&ctrl->ana_work);
+	timer_delete_sync(&ctrl->anatt_timer);
 }
 
 #define SUBSYS_ATTR_RW(_name, _mode, _show, _store)  \
@@ -1647,6 +1647,7 @@ void nvme_mpath_uninit(struct nvme_ctrl *ctrl)
 	 * resources.
 	 */
 	cancel_work_sync(&ctrl->ana_work);
+	timer_delete_sync(&ctrl->anatt_timer);
 
 	kvfree(ctrl->ana_log_buf);
 	ctrl->ana_log_buf = NULL;
-- 
2.43.7



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

end of thread, other threads:[~2026-11-30 15:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 12:13 [PATCH] nvme-multipath: delete the ANATT timer after draining ana_work Guixin Liu
2026-11-24 12:22 ` sashiko-bot
2026-11-24 12:35   ` Guixin Liu
2026-11-25  5:16 ` Christoph Hellwig
2026-11-25  8:25 ` Hannes Reinecke
2026-11-25  9:47 ` Nilay Shroff
2026-11-30 15:56 ` Keith Busch

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