[PATCH] nvme-multipath: protect ana_log_buf teardown with ana_lock
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Tue Nov 24 22:10:21 PST 2026
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 at 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
More information about the Linux-nvme
mailing list