[PATCH] nvme-pci: validate dmabuf size and sg_table bounds in nvme_dma_buf_io_map()

Keith Busch kbusch at kernel.org
Wed Dec 2 07:15:35 PST 2026


On Tue, 01 Dec 2026 14:39:11 +0800, Bilal Hashim wrote:
> 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.
> 
> [...]

Thanks, applied to nvme-7.4.

[1/1] nvme-pci: validate dmabuf size and sg_table bounds in nvme_dma_buf_io_map()
      commit: 1ff946ecf80bcbc929ba5f80812b1f4646cf19c7
--
Keith Busch <kbusch at kernel.org>




More information about the Linux-nvme mailing list