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 v9 07/13] nvme-pci: implement dma-buf backed requests
Date: Wed, 07 Oct 2026 02:01:56 +0000 [thread overview]
Message-ID: <sashiko-outbox-162578@kernel.org> (raw)
In-Reply-To: <624ec2c9b2118a97b4e5f425f0951e09c118deb5.1791336930.git.asml.silence@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] block: nvme: heap buffer overflow in nvme_dma_buf_io_map() due to missing bounds check
--
commit 6ab5bd531acb81cbd400d2dec375c79d1f832e58
Author: Pavel Begunkov <asml.silence@gmail.com>
nvme-pci: implement dma-buf backed requests
This patch enables BIO_DMABUF_MAP backed requests. On registration, it maps
the dma-buf and stores it as a prp list used to initialize requests. All
attached contexts are stored in a new list dmabuf_ctxs, and synchronized
with dmabuf_lock.
> diff --git a/drivers/nvme/host/pci-dmabuf.c b/drivers/nvme/host/pci-dmabuf.c
> new file mode 100644
> index 0000000000000..d58a38a75d673
> --- /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: High]
Does this code overflow the map->dma_list[] flex array if the total mapped
length exceeds the calculated ctx->dmabuf->size?
nvme_dma_buf_io_map() calculates the number of flex array entries (nr_entries)
based strictly on ctx->dmabuf->size. However, the loop that populates
map->dma_list is bounded by the total sg_dma_len(sg) across all entries in the
scatterlist returned by dma_buf_map_attachment().
The DMA mapping API explicitly allows the mapped DMA length (sg_dma_len) to be
larger than the original buffer size. For instance, this can occur when an
IOMMU coalesces entries or aligns sizes to a larger IOMMU page size. A buggy
exporter could also supply a larger-than-expected scatterlist.
Without bounds-checking i against nr_entries, writing to map->dma_list[i++]
could result in a heap buffer overflow.
> + dma_addr += NVME_CTRL_PAGE_SIZE;
> + sg_len -= NVME_CTRL_PAGE_SIZE;
> + }
> + }
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1791336930.git.asml.silence@gmail.com?part=7
next prev parent reply other threads:[~2026-10-07 2:01 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-07 1:42 [PATCH v9 00/13] Add dmabuf read/write via io_uring Pavel Begunkov
2026-10-07 1:42 ` [PATCH v9 01/13] dma-buf: introduce initial file I/O infrastructure Pavel Begunkov
2026-10-07 1:52 ` sashiko-bot
2026-10-07 1:42 ` [PATCH v9 02/13] iov_iter: add iterator type for dmabuf maps Pavel Begunkov
2026-10-07 1:57 ` sashiko-bot
2026-10-07 1:42 ` [PATCH v9 03/13] block: always adjust bi_offset on bio_advance_iter Pavel Begunkov
2026-10-07 1:42 ` [PATCH v9 04/13] block: introduce dma map backed bio type Pavel Begunkov
2026-10-07 1:59 ` sashiko-bot
2026-10-07 1:42 ` [PATCH v9 05/13] block: add dma-buf support for raw bdev Pavel Begunkov
2026-10-07 1:42 ` [PATCH v9 06/13] nvme-pci: rename nvme_pci_sgl_set_data to nvme_pci_dma_iter_set_sgl Pavel Begunkov
2026-10-07 1:42 ` [PATCH v9 07/13] nvme-pci: implement dma-buf backed requests Pavel Begunkov
2026-10-07 2:01 ` sashiko-bot [this message]
2026-10-07 1:42 ` [PATCH v9 08/13] nvme-pci: add SGL support for the dmabuf path Pavel Begunkov
2026-10-07 2:00 ` sashiko-bot
2026-10-07 1:42 ` [PATCH v9 09/13] io_uring/rsrc: introduce buf registration structure Pavel Begunkov
2026-10-07 1:42 ` [PATCH v9 10/13] io_uring/rsrc: extend buffer update Pavel Begunkov
2026-10-07 1:51 ` sashiko-bot
2026-10-07 1:42 ` [PATCH v9 11/13] io_uring/rsrc: add uncloneable regbuf flag Pavel Begunkov
2026-10-07 1:42 ` [PATCH v9 12/13] io_uring/rsrc: add regbuf import flags Pavel Begunkov
2026-10-07 1:42 ` [PATCH v9 13/13] io_uring/rsrc: add dmabuf backed registered buffers Pavel Begunkov
2026-10-07 1:55 ` 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=sashiko-outbox-162578@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox