[PATCH] nvme-pci: validate dmabuf size and sg_table bounds in nvme_dma_buf_io_map()
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Mon Nov 30 22:44:11 PST 2026
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] nvme-pci: missing Fixes trailer for nvme_dma_buf_io_map() bounds
fix
--
commit 0f211451ecf8fb8b6438a1ca1c4bb449732f7069
Author: Bilal Hashim <AeeSec at 126.com>
> nvme-pci: validate dmabuf size and sg_table bounds in nvme_dma_buf_io_map()
>
> In nvme_dma_buf_io_map():
>
> 1. ctx->dmabuf->size (size_t) is divided by NVME_CTRL_PAGE_SIZE and
> stored into a 32-bit unsigned nr_entries without checking for zero or
> overflow, and nvme_rq_setup_dmabuf_map() indexes the buffer via the
> 32-bit bio->bi_iter.bi_offset. Reject empty dma-bufs or dma-bufs
> larger than UINT_MAX.
> 2. When populating map->dma_list[] from the scatter-gather table, there
> is no bounds check against nr_entries. If the sg_table total DMA
> length exceeds nr_entries * NVME_CTRL_PAGE_SIZE, map->dma_list[i++]
> overflows the allocated buffer. Conversely, if the sg_table total DMA
> length is smaller than nr_entries * NVME_CTRL_PAGE_SIZE, trailing
> entries in map->dma_list[] remain uninitialized (kvmalloc_flex() does
> not zero-initialize) and could be programmed as arbitrary NVMe DMA
> addresses.
>
> Validate ctx->dmabuf->size before computing nr_entries, bounds-check
> each write into map->dma_list[], and verify that the entire dma_list was
> populated.
>
> Found by manual code inspection.
>
> Signed-off-by: Bilal Hashim <AeeSec at 126.com>
[Severity: Low]
This fixes missing size and scatter-gather bounds checks in
nvme_dma_buf_io_map(). Should this include:
Fixes: ce5e386c1108 ("nvme-pci: implement dma-buf backed requests")
--
Sashiko AI review · https://sashiko.dev/#/patchset/179610715173.42980.4278125034253504647@126.com?part=1
More information about the Linux-nvme
mailing list