[PATCH] nvme-multipath: delete the ANATT timer after draining ana_work
Guixin Liu
kanie at linux.alibaba.com
Tue Nov 24 04:35:51 PST 2026
在 2026/11/24 20:22, sashiko-bot at 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 at 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
>
More information about the Linux-nvme
mailing list