* Re: [PATCH] nvme-multipath: delete the ANATT timer after draining ana_work
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
` (3 subsequent siblings)
4 siblings, 1 reply; 7+ messages in thread
From: sashiko-bot @ 2026-11-24 12:22 UTC (permalink / raw)
To: Guixin Liu; +Cc: linux-nvme
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] nvme-multipath: use-after-free in nvme_parse_ana_log() [1]
--
commit e4ad87877e854ebed2991236e7f5c8c425e05678
Author: Guixin Liu <kanie@linux.alibaba.com>
nvme-multipath: delete the ANATT timer after draining ana_work
This commit cancels ana_work before deleting anatt_timer in
nvme_mpath_stop() and also deletes the timer in nvme_mpath_uninit() after
draining ana_work.
> diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
> index 27facdbb3d4c0..40f6cab3db47c 100644
> --- a/drivers/nvme/host/multipath.c
> +++ b/drivers/nvme/host/multipath.c
[ ... ]
> @@ -1614,6 +1614,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;
[Severity: Critical]
This problem wasn't introduced by this patch, but can freeing
ctrl->ana_log_buf here without holding ctrl->ana_lock cause a
use-after-free in nvme_parse_ana_log() [1]?
When nvme_mpath_init_identify() sees a larger ana_log_size, it calls
nvme_mpath_uninit() to free the old buffer before allocating a new one,
without taking ctrl->ana_lock. A concurrent namespace scan in
nvme_mpath_add_disk() takes ctrl->ana_lock and reads ctrl->ana_log_buf in
nvme_parse_ana_log():
CPU0 CPU1
nvme_mpath_init_identify() nvme_mpath_add_disk()
if (nvme_ctrl_use_ana(ns->ctrl))
mutex_lock(&ns->ctrl->ana_lock)
nvme_parse_ana_log()
base = ctrl->ana_log_buf
nvme_mpath_uninit()
kvfree(ctrl->ana_log_buf)
/* dereferences freed base */
<-- use-after-free
Taking ctrl->ana_lock around freeing and replacing ctrl->ana_log_buf would
serialize this with concurrent readers.
[1] https://sashiko.dev/#/bug/linux-48603474-5139-4b24-a567-ce7f9706b201
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124121349.1861269-1-kanie@linux.alibaba.com?part=1
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] nvme-multipath: delete the ANATT timer after draining ana_work
2026-11-24 12:22 ` sashiko-bot
@ 2026-11-24 12:35 ` Guixin Liu
0 siblings, 0 replies; 7+ messages in thread
From: Guixin Liu @ 2026-11-24 12:35 UTC (permalink / raw)
To: sashiko-reviews; +Cc: linux-nvme
在 2026/11/24 20:22, sashiko-bot@kernel.org 写道:
> 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] nvme-multipath: use-after-free in nvme_parse_ana_log() [1]
> --
>
> commit e4ad87877e854ebed2991236e7f5c8c425e05678
> Author: Guixin Liu <kanie@linux.alibaba.com>
>
> nvme-multipath: delete the ANATT timer after draining ana_work
>
> This commit cancels ana_work before deleting anatt_timer in
> nvme_mpath_stop() and also deletes the timer in nvme_mpath_uninit() after
> draining ana_work.
>
>> diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
>> index 27facdbb3d4c0..40f6cab3db47c 100644
>> --- a/drivers/nvme/host/multipath.c
>> +++ b/drivers/nvme/host/multipath.c
> [ ... ]
>
>> @@ -1614,6 +1614,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;
> [Severity: Critical]
> This problem wasn't introduced by this patch, but can freeing
> ctrl->ana_log_buf here without holding ctrl->ana_lock cause a
> use-after-free in nvme_parse_ana_log() [1]?
>
> When nvme_mpath_init_identify() sees a larger ana_log_size, it calls
> nvme_mpath_uninit() to free the old buffer before allocating a new one,
> without taking ctrl->ana_lock. A concurrent namespace scan in
> nvme_mpath_add_disk() takes ctrl->ana_lock and reads ctrl->ana_log_buf in
> nvme_parse_ana_log():
>
> CPU0 CPU1
> nvme_mpath_init_identify() nvme_mpath_add_disk()
> if (nvme_ctrl_use_ana(ns->ctrl))
> mutex_lock(&ns->ctrl->ana_lock)
> nvme_parse_ana_log()
> base = ctrl->ana_log_buf
> nvme_mpath_uninit()
> kvfree(ctrl->ana_log_buf)
> /* dereferences freed base */
> <-- use-after-free
>
> Taking ctrl->ana_lock around freeing and replacing ctrl->ana_log_buf would
> serialize this with concurrent readers.
>
> [1] https://sashiko.dev/#/bug/linux-48603474-5139-4b24-a567-ce7f9706b201
What Sashiko found is a pre-existing bug, not something introduced by this patch.
Let me check wheather I can send a separate patch for it.
Best Regards,
Guixin Liu
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] nvme-multipath: delete the ANATT timer after draining ana_work
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-25 5:16 ` Christoph Hellwig
2026-11-25 8:25 ` Hannes Reinecke
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2026-11-25 5:16 UTC (permalink / raw)
To: Guixin Liu
Cc: Keith Busch, Jens Axboe, Sagi Grimberg, Nilay Shroff,
Daniel Wagner, Hannes Reinecke, linux-nvme
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] nvme-multipath: delete the ANATT timer after draining ana_work
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-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
4 siblings, 0 replies; 7+ messages in thread
From: Hannes Reinecke @ 2026-11-25 8:25 UTC (permalink / raw)
To: Guixin Liu, Keith Busch, Jens Axboe, Christoph Hellwig,
Sagi Grimberg, Nilay Shroff, Daniel Wagner
Cc: linux-nvme
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@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(-)
>
Reviewed-by: Hannes Reinecke <hare@kernel.org>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@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
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] nvme-multipath: delete the ANATT timer after draining ana_work
2026-11-24 12:13 [PATCH] nvme-multipath: delete the ANATT timer after draining ana_work Guixin Liu
` (2 preceding siblings ...)
2026-11-25 8:25 ` Hannes Reinecke
@ 2026-11-25 9:47 ` Nilay Shroff
2026-11-30 15:56 ` Keith Busch
4 siblings, 0 replies; 7+ messages in thread
From: Nilay Shroff @ 2026-11-25 9:47 UTC (permalink / raw)
To: Guixin Liu, Keith Busch, Jens Axboe, Christoph Hellwig,
Sagi Grimberg, Daniel Wagner, Hannes Reinecke
Cc: linux-nvme
On 11/24/26 5:43 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@vger.kernel.org
> Signed-off-by: Guixin Liu<kanie@linux.alibaba.com>
Looks good to me:
Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] nvme-multipath: delete the ANATT timer after draining ana_work
2026-11-24 12:13 [PATCH] nvme-multipath: delete the ANATT timer after draining ana_work Guixin Liu
` (3 preceding siblings ...)
2026-11-25 9:47 ` Nilay Shroff
@ 2026-11-30 15:56 ` Keith Busch
4 siblings, 0 replies; 7+ messages in thread
From: Keith Busch @ 2026-11-30 15:56 UTC (permalink / raw)
To: Jens Axboe, Christoph Hellwig, Sagi Grimberg, Nilay Shroff,
Daniel Wagner, Hannes Reinecke, Guixin Liu
Cc: linux-nvme
On Tue, 24 Nov 2026 20:13:49 +0800, 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.
>
> [...]
Thanks, applied to nvme-7.4.
[1/1] nvme-multipath: delete the ANATT timer after draining ana_work
commit: 083775310ce4fa21fa80f82b852f85de05f30329
--
Keith Busch <kbusch@kernel.org>
^ permalink raw reply [flat|nested] 7+ messages in thread