From: sashiko-bot@kernel.org
To: "Pavel Begunkov" <asml.silence@gmail.com>
Cc: dri-devel@lists.freedesktop.org, media-ci@linuxtv.org
Subject: Re: [PATCH v10 07/13] nvme-pci: implement dma-buf backed requests
Date: Tue, 13 Oct 2026 21:23:35 +0000 [thread overview]
Message-ID: <sashiko-outbox-170530@kernel.org> (raw)
In-Reply-To: <a8c9ff112d4295e7a3f7c361e03f03ee5eb42e74.1791924581.git.asml.silence@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] nvme: missing controller state check allows attaching DMA-BUF to dead PCI device
--
commit 6741fe43dc1132ae4f51db272567ac5b56987f17
Author: Pavel Begunkov <asml.silence@gmail.com>
nvme-pci: implement dma-buf backed requests
This patch implements DMA-BUF backed requests for the NVMe PCI driver. It
allows mapping DMA-BUFs on registration and storing them as a PRP list to
initialize requests. Attached contexts are tracked in a new list
synchronized with a lock.
> diff --git a/drivers/nvme/host/pci-dmabuf.c b/drivers/nvme/host/pci-dmabuf.c
> new file mode 100644
> index 0000000000000..8dab59d936507
> --- /dev/null
> +++ b/drivers/nvme/host/pci-dmabuf.c
[ ... ]
> +static int nvme_init_io_ctx_locked(struct nvme_ctrl *ctrl,
> + struct nvme_dma_buf_list *buf_list,
> + struct dma_buf_io_ctx *ctx)
> +{
> + struct nvme_dma_buf_io_ctx *nvme_ctx;
> + struct dma_buf_attachment *attach;
> +
> + nvme_ctx = kzalloc_obj(*nvme_ctx);
> + if (!nvme_ctx)
> + return -ENOMEM;
> +
> + attach = dma_buf_dynamic_attach(ctx->dmabuf, ctrl->dev,
> + &nvme_dmabuf_importer_ops, ctx);
[Severity: High]
Does this code allow attaching a DMA-BUF to a tearing-down or dead PCI device?
If the PCI device is hot-unplugged or its driver is unbound, nvme_remove()
calls nvme_dev_disable() which cleans up existing DMA-BUF contexts via
nvme_pci_remove_dmabuf().
Since nvme_get_ctrl() only pins the char device, not the underlying
PCI device binding, could an unprivileged user with an open file descriptor
to the block device invoke the register buffers ioctl and race with
device removal?
> + if (IS_ERR(attach)) {
> + kfree(nvme_ctx);
> + return PTR_ERR(attach);
> + }
> +
> + nvme_get_ctrl(ctrl);
> + list_add(&nvme_ctx->list, &buf_list->ctxs);
> + nvme_ctx->attach = attach;
> + nvme_ctx->base = ctx;
> + nvme_ctx->ctrl = ctrl;
> + nvme_ctx->buf_list = buf_list;
> + ctx->dev_priv = nvme_ctx;
> + ctx->dev_ops = &nvme_dma_buf_io_ops;
> + return 0;
> +}
> +
> +int __nvme_init_dma_buf_io_ctx(struct nvme_ctrl *ctrl,
> + struct nvme_dma_buf_list *buf_list,
> + struct dma_buf_io_ctx *ctx)
> +{
> + int ret;
> +
> + mutex_lock(&buf_list->lock);
> + ret = nvme_init_io_ctx_locked(ctrl, buf_list, ctx);
[Severity: High]
Is a controller state check needed here before proceeding with the attachment?
Without verifying ctrl->state, this function can successfully add a new
attachment to the device's list, mapping it to a PCI device that is no
longer managed by the driver. This could lead to IOMMU domain use-after-free
or memory leaks.
> + mutex_unlock(&buf_list->lock);
> + return ret;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1791924581.git.asml.silence@gmail.com?part=7
next prev parent reply other threads:[~2026-10-13 21:23 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 20:54 [PATCH v10 00/13] Add dmabuf read/write via io_uring Pavel Begunkov
2026-10-13 20:54 ` [PATCH v10 01/13] dma-buf: introduce initial file I/O infrastructure Pavel Begunkov
2026-10-13 21:06 ` sashiko-bot
2026-10-13 20:54 ` [PATCH v10 02/13] iov_iter: add iterator type for dmabuf maps Pavel Begunkov
2026-10-13 21:13 ` sashiko-bot
2026-10-13 20:54 ` [PATCH v10 03/13] block: always adjust bi_offset on bio_advance_iter Pavel Begunkov
2026-10-13 20:54 ` [PATCH v10 04/13] block: introduce dma map backed bio type Pavel Begunkov
2026-10-13 20:54 ` [PATCH v10 05/13] block: add dma-buf support for raw bdev Pavel Begunkov
2026-10-13 20:54 ` [PATCH v10 06/13] nvme-pci: rename nvme_pci_sgl_set_data to nvme_pci_dma_iter_set_sgl Pavel Begunkov
2026-10-13 20:54 ` [PATCH v10 07/13] nvme-pci: implement dma-buf backed requests Pavel Begunkov
2026-10-13 21:23 ` sashiko-bot [this message]
2026-10-13 20:54 ` [PATCH v10 08/13] nvme-pci: add SGL support for the dmabuf path Pavel Begunkov
2026-10-13 20:54 ` [PATCH v10 09/13] io_uring/rsrc: introduce buf registration structure Pavel Begunkov
2026-10-13 20:54 ` [PATCH v10 10/13] io_uring/rsrc: extend buffer update Pavel Begunkov
2026-10-13 20:54 ` [PATCH v10 11/13] io_uring/rsrc: add uncloneable regbuf flag Pavel Begunkov
2026-10-13 20:54 ` [PATCH v10 12/13] io_uring/rsrc: add regbuf import flags Pavel Begunkov
2026-10-13 20:54 ` [PATCH v10 13/13] io_uring/rsrc: add dmabuf backed registered buffers Pavel Begunkov
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-170530@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=asml.silence@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=media-ci@linuxtv.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.