Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Guixin Liu <kanie@linux.alibaba.com>
To: sashiko-reviews@lists.linux.dev
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH] nvme-multipath: delete the ANATT timer after draining ana_work
Date: Tue, 24 Nov 2026 20:35:51 +0800	[thread overview]
Message-ID: <e7e925d7-27e9-4961-b405-aef832525dba@linux.alibaba.com> (raw)
In-Reply-To: <sashiko-outbox-231129@kernel.org>



在 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
>



  reply	other threads:[~2026-11-24 12:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e7e925d7-27e9-4961-b405-aef832525dba@linux.alibaba.com \
    --to=kanie@linux.alibaba.com \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox