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 v11 07/13] nvme-pci: implement dma-buf backed requests
Date: Wed, 14 Oct 2026 11:26:57 +0000 [thread overview]
Message-ID: <sashiko-outbox-171198@kernel.org> (raw)
In-Reply-To: <9540e74b5d2dd1a5dc0d436bc0c2a6f5e18fc389.1791975048.git.asml.silence@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] nvme: heap buffer overflow in nvme_dma_buf_io_map() on oversized sg_table
--
commit c0ad27ffb27d58a9a9cd8c22288b3a3645727e63
Author: Pavel Begunkov <asml.silence@gmail.com>
nvme-pci: implement dma-buf backed requests
This commit adds support for DMA-buf backed requests in the NVMe PCI host
driver. On registration, the dma-buf is mapped and stored as a prp list to
initialize requests. All attached contexts are stored in a new list
synchronized with a mutex.
> diff --git a/drivers/nvme/host/pci-dmabuf.c b/drivers/nvme/host/pci-dmabuf.c
> new file mode 100644
> index 0000000000000..161e4ffa6919b
> --- /dev/null
> +++ b/drivers/nvme/host/pci-dmabuf.c
[ ... ]
> +static struct dma_buf_io_map *nvme_dma_buf_io_map(struct dma_buf_io_ctx *ctx)
> +{
> + unsigned nr_entries = ctx->dmabuf->size / NVME_CTRL_PAGE_SIZE;
> + struct nvme_dma_buf_io_ctx *nvme_ctx = ctx->dev_priv;
> + struct dma_buf_attachment *attach = nvme_ctx->attach;
> + unsigned long tmp, i = 0;
> + struct nvme_dmabuf_map *map;
> + struct scatterlist *sg;
> + struct sg_table *sgt;
> + int ret;
> +
> + dma_resv_assert_held(ctx->dmabuf->resv);
> +
> + if (ctx->dmabuf->size % NVME_CTRL_PAGE_SIZE)
> + return ERR_PTR(-EINVAL);
> +
> + map = kvmalloc_flex(*map, dma_list, nr_entries);
> + if (!map)
> + return ERR_PTR(-ENOMEM);
> + map->nr_entries = nr_entries;
> +
> + sgt = dma_buf_map_attachment(attach, ctx->dir);
> + if (IS_ERR(sgt)) {
> + ret = PTR_ERR(sgt);
> + sgt = NULL;
> + goto err;
> + }
> +
> + for_each_sgtable_dma_sg(sgt, sg, tmp) {
> + dma_addr_t dma_addr = sg_dma_address(sg);
> + unsigned long sg_len = sg_dma_len(sg);
> +
> + if ((sg_len % NVME_CTRL_PAGE_SIZE) ||
> + (dma_addr % NVME_CTRL_PAGE_SIZE)) {
> + ret = -EINVAL;
> + goto err;
> + }
> + while (sg_len) {
> + map->dma_list[i++] = dma_addr;
[Severity: Critical]
Could this lead to a heap buffer overflow?
The flex array map->dma_list is allocated with a fixed capacity of
nr_entries, which is derived strictly from ctx->dmabuf->size.
However, this loop populates the array based on the total length of the
sg_table returned by dma_buf_map_attachment().
Because dma_buf_map_attachment() does not enforce that the returned
sg_table's length matches dmabuf->size, a buggy or malicious exporter
could return a larger table. In that case, i would exceed nr_entries
without any bounds check, leading to an out-of-bounds write. This
could allow memory corruption triggerable by unprivileged users capable
of creating and exporting dmabufs.
> + dma_addr += NVME_CTRL_PAGE_SIZE;
> + sg_len -= NVME_CTRL_PAGE_SIZE;
> + }
> + }
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1791975048.git.asml.silence@gmail.com?part=7
next prev parent reply other threads:[~2026-10-14 11:27 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 11:01 [PATCH v11 00/13] Add dmabuf read/write via io_uring Pavel Begunkov
2026-10-14 11:01 ` [PATCH v11 01/13] dma-buf: introduce initial file I/O infrastructure Pavel Begunkov
2026-10-14 11:13 ` sashiko-bot
2026-10-14 12:30 ` Christian König
2026-10-14 13:06 ` Pavel Begunkov
2026-10-14 11:02 ` [PATCH v11 02/13] iov_iter: add iterator type for dmabuf maps Pavel Begunkov
2026-10-14 11:02 ` [PATCH v11 03/13] block: always adjust bi_offset on bio_advance_iter Pavel Begunkov
2026-10-14 11:02 ` [PATCH v11 04/13] block: introduce dma map backed bio type Pavel Begunkov
2026-10-14 11:21 ` sashiko-bot
2026-10-14 13:03 ` Pavel Begunkov
2026-10-14 13:15 ` Christoph Hellwig
2026-10-14 16:43 ` Pavel Begunkov
2026-10-14 11:02 ` [PATCH v11 05/13] block: add dma-buf support for raw bdev Pavel Begunkov
2026-10-14 11:02 ` [PATCH v11 06/13] nvme-pci: rename nvme_pci_sgl_set_data to nvme_pci_dma_iter_set_sgl Pavel Begunkov
2026-10-14 11:02 ` [PATCH v11 07/13] nvme-pci: implement dma-buf backed requests Pavel Begunkov
2026-10-14 11:26 ` sashiko-bot [this message]
2026-10-14 13:16 ` Christoph Hellwig
2026-10-14 11:02 ` [PATCH v11 08/13] nvme-pci: add SGL support for the dmabuf path Pavel Begunkov
2026-10-14 11:23 ` sashiko-bot
2026-10-14 13:16 ` Christoph Hellwig
2026-10-14 11:02 ` [PATCH v11 09/13] io_uring/rsrc: introduce buf registration structure Pavel Begunkov
2026-10-14 11:02 ` [PATCH v11 10/13] io_uring/rsrc: extend buffer update Pavel Begunkov
2026-10-14 11:02 ` [PATCH v11 11/13] io_uring/rsrc: add uncloneable regbuf flag Pavel Begunkov
2026-10-14 11:02 ` [PATCH v11 12/13] io_uring/rsrc: add regbuf import flags Pavel Begunkov
2026-10-14 11:02 ` [PATCH v11 13/13] io_uring/rsrc: add dmabuf backed registered buffers Pavel Begunkov
2026-10-14 11:18 ` sashiko-bot
2026-10-14 13:40 ` Jens Axboe
2026-10-14 13:43 ` [PATCH v11 00/13] Add dmabuf read/write via io_uring Jens Axboe
2026-10-14 14:37 ` Anuj gupta
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-171198@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.