From: sashiko-bot@kernel.org
To: "John Garry" <john.g.garry@oracle.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v3 05/10] nvme-multipath: add nvme_mpath_cdev_ioctl()
Date: Fri, 03 Jul 2026 11:11:44 +0000 [thread overview]
Message-ID: <20260703111145.4EA151F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260703103204.3724406-6-john.g.garry@oracle.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Accessing `ns->ctrl` in `_nvme_ns_chr_ioctl()` leads to a Use-After-Free because the SRCU read lock protecting the namespace is dropped by the caller.
- [Critical] `nvme_mpath_ioctl_begin()` fails to initialize `*data` for non-controller ioctls, causing a NULL pointer dereference or crash in `nvme_mpath_ioctl_finish()`.
--
commit 7c14abcc0f25bf0d710bcb67c0dbd7f7f3dc3774
Author: John Garry <john.g.garry@oracle.com>
nvme-multipath: add nvme_mpath_cdev_ioctl()
This commit adds nvme_mpath_cdev_ioctl() and related ioctl lifecycle
callbacks to handle SRCU read lock dropping during controller command
IOCTL handling for NVMe multipath character devices.
> diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c
> index 664216eece4a6..14ac86b8b1a8a 100644
> --- a/drivers/nvme/host/ioctl.c
> +++ b/drivers/nvme/host/ioctl.c
[ ... ]
> @@ -689,6 +695,29 @@ int nvme_ns_chr_uring_cmd_iopoll(struct io_uring_cmd *ioucmd,
> return 0;
> }
> #ifdef CONFIG_NVME_MULTIPATH
> +long nvme_mpath_cdev_ioctl(struct mpath_device *mpath_device, unsigned int cmd,
> + unsigned long arg, bool open_for_write)
> +{
> + return _nvme_ns_chr_ioctl(nvme_mpath_to_ns(mpath_device), cmd,
> + arg, open_for_write);
> +}
[Severity: Critical]
Could this lead to a use-after-free on the namespace object?
When a userspace program issues a controller ioctl on a multipath char device,
the generic mpath_chr_ioctl() drops the SRCU read lock before calling
nvme_mpath_cdev_ioctl().
While nvme_mpath_ioctl_begin() takes a reference to the controller, the
namespace object itself is left unprotected during this window. If the
namespace is concurrently removed, passing the unprotected ns pointer down to
_nvme_ns_chr_ioctl() and dereferencing ns->ctrl could access freed memory.
> +
> +void nvme_mpath_ioctl_begin(struct mpath_device *mpath_device,
> + unsigned int cmd, void **data)
> +{
> + struct nvme_ctrl *ctrl = nvme_mpath_to_ns(mpath_device)->ctrl;
> +
> + if (is_ctrl_ioctl(cmd)) {
> + nvme_get_ctrl(ctrl);
> + *data = ctrl;
> + }
> +}
[Severity: Critical]
Does this leave *data uninitialized or unmodified for non-controller ioctls?
If a user issues a standard ioctl (like NVME_IOCTL_ID), is_ctrl_ioctl(cmd)
will evaluate to false, meaning *data is not assigned here.
> +
> +void nvme_mpath_ioctl_finish(void *opaque)
> +{
> + nvme_put_ctrl(opaque);
> +}
[Severity: Critical]
Is it safe to unconditionally call nvme_put_ctrl() here?
If nvme_mpath_ioctl_begin() did not set *data (because it was not a controller
ioctl), opaque might be NULL or uninitialized garbage.
Calling nvme_put_ctrl() unconditionally:
static inline void nvme_put_ctrl(struct nvme_ctrl *ctrl)
{
put_device(ctrl->device);
}
will dereference ctrl->device, which could result in a panic if opaque is NULL
or an invalid pointer. Should there be a check before calling nvme_put_ctrl()?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260703103204.3724406-1-john.g.garry@oracle.com?part=5
next prev parent reply other threads:[~2026-07-03 11:11 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-03 10:31 [PATCH v3 00/10] nvme: switch to libmultipath John Garry
2026-07-03 10:31 ` [PATCH v3 01/10] nvme-multipath: add initial support for using libmultipath John Garry
2026-07-03 10:44 ` sashiko-bot
2026-07-03 10:31 ` [PATCH v3 02/10] nvme-multipath: add nvme_mpath_available_path() John Garry
2026-07-03 10:31 ` [PATCH v3 03/10] nvme-multipath: add nvme_mpath_{add, remove}_cdev() John Garry
2026-07-03 10:31 ` [PATCH v3 04/10] nvme-multipath: add nvme_mpath_is_{disabled, optimised} John Garry
2026-07-03 11:06 ` sashiko-bot
2026-07-03 10:31 ` [PATCH v3 05/10] nvme-multipath: add nvme_mpath_cdev_ioctl() John Garry
2026-07-03 11:11 ` sashiko-bot [this message]
2026-07-03 10:32 ` [PATCH v3 06/10] nvme-multipath: add uring_cmd support John Garry
2026-07-03 11:42 ` sashiko-bot
2026-07-03 10:32 ` [PATCH v3 07/10] nvme-multipath: add nvme_mpath_synchronize() John Garry
2026-07-03 11:24 ` sashiko-bot
2026-07-03 14:50 ` John Garry
2026-07-03 10:32 ` [PATCH v3 08/10] nvme-multipath: add nvme_{add,delete}_ns() John Garry
2026-07-03 11:24 ` sashiko-bot
2026-07-03 10:32 ` [PATCH v3 09/10] nvme-multipath: add nvme_mpath_head_queue_if_no_path() John Garry
2026-07-03 11:33 ` sashiko-bot
2026-07-03 10:32 ` [PATCH v3 10/10] nvme-multipath: switch to use libmultipath John Garry
2026-07-03 11:42 ` sashiko-bot
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=20260703111145.4EA151F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=john.g.garry@oracle.com \
--cc=linux-scsi@vger.kernel.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