Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Guixin Liu" <kanie@linux.alibaba.com>
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH] nvme-multipath: protect ana_log_buf teardown with ana_lock
Date: Wed, 25 Nov 2026 06:10:21 +0000	[thread overview]
Message-ID: <sashiko-outbox-232646@kernel.org> (raw)
In-Reply-To: <20261125060153.206699-1-kanie@linux.alibaba.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] nvme-multipath: NULL deref and uninit read in
  nvme_parse_ana_log()
--

commit d312e34ea57a3e103965fa1cad1dd210a8ca3b3a
Author: Guixin Liu <kanie@linux.alibaba.com>

nvme-multipath: protect ana_log_buf teardown with ana_lock

This commit acquires ctrl->ana_lock around freeing and clearing
ctrl->ana_log_buf in nvme_mpath_uninit() to serialize against concurrent
ANA log parsers.

> diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
> index 27facdbb3d4c0..bc0abd1f30274 100644
> --- a/drivers/nvme/host/multipath.c
> +++ b/drivers/nvme/host/multipath.c
> @@ -1615,7 +1615,9 @@ void nvme_mpath_uninit(struct nvme_ctrl *ctrl)
>  	 */
>  	cancel_work_sync(&ctrl->ana_work);
>  
> +	mutex_lock(&ctrl->ana_lock);
>  	kvfree(ctrl->ana_log_buf);
>  	ctrl->ana_log_buf = NULL;
>  	ctrl->ana_log_size = 0;
> +	mutex_unlock(&ctrl->ana_lock);
>  }

[Severity: High]
Can a concurrent parser in nvme_mpath_add_disk() still hit a NULL pointer
dereference or read uninitialized memory in nvme_parse_ana_log() when
nvme_mpath_uninit() unlocks ctrl->ana_lock?

In the concurrent nvme_mpath_init_identify() and nvme_mpath_add_disk()
path, nvme_mpath_add_disk() checks nvme_ctrl_use_ana() (which tests
ctrl->ana_log_buf != NULL) before acquiring ctrl->ana_lock, and
nvme_parse_ana_log() unconditionally dereferences
ctrl->ana_log_buf->ngrps:

CPU0                                  CPU1
nvme_mpath_init_identify()            nvme_mpath_add_disk()
                                        if (nvme_ctrl_use_ana(ctrl))
  nvme_mpath_uninit()
    mutex_lock(&ctrl->ana_lock)
    kvfree(ctrl->ana_log_buf)
    ctrl->ana_log_buf = NULL
    mutex_unlock(&ctrl->ana_lock)
                                        mutex_lock(&ctrl->ana_lock)
                                        nvme_parse_ana_log()
                                          ctrl->ana_log_buf->ngrps
                                            <-- NULL pointer dereference
  ctrl->ana_log_buf = kvmalloc(...)
  nvme_read_ana_log()

Even if CPU1 acquires ctrl->ana_lock after kvmalloc() runs in
nvme_mpath_init_identify(), ctrl->ana_log_buf and ctrl->ana_log_size are
assigned before nvme_read_ana_log() retakes ctrl->ana_lock to populate the
buffer, so nvme_parse_ana_log() can parse uninitialized memory from
kvmalloc().  In addition, while ctrl->ana_log_buf is NULL between
nvme_mpath_uninit() and kvmalloc(), concurrent callers of
nvme_ctrl_use_ana() transiently observe the controller as non-ANA.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125060153.206699-1-kanie@linux.alibaba.com?part=1


      reply	other threads:[~2026-11-25  6:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  6:01 [PATCH] nvme-multipath: protect ana_log_buf teardown with ana_lock Guixin Liu
2026-11-25  6:10 ` sashiko-bot [this message]

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=sashiko-outbox-232646@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=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