[PATCH] nvme-multipath: delete the ANATT timer after draining ana_work

Hannes Reinecke hare at suse.de
Wed Nov 25 00:25:11 PST 2026


On 11/24/26 1:13 PM, Guixin Liu wrote:
> 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 at vger.kernel.org
> Signed-off-by: Guixin Liu <kanie at 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(-)
> 
Reviewed-by: Hannes Reinecke <hare at kernel.org>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                  Kernel Storage Architect
hare at suse.de                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich



More information about the Linux-nvme mailing list