[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251128124447.0c5156b5.alex@shazbot.org>
Date: Fri, 28 Nov 2025 12:44:47 -0700
From: Alex Williamson <alex@...zbot.org>
To: Alex Mastro <amastro@...com>
Cc: Sumit Semwal <sumit.semwal@...aro.org>, Christian König
<christian.koenig@....com>, Leon Romanovsky <leon@...nel.org>, Jason
Gunthorpe <jgg@...pe.ca>, "Kevin Tian" <kevin.tian@...el.com>, Nicolin Chen
<nicolinc@...dia.com>, <linux-media@...r.kernel.org>,
<dri-devel@...ts.freedesktop.org>, <linaro-mm-sig@...ts.linaro.org>,
<linux-kernel@...r.kernel.org>, <kvm@...r.kernel.org>, Ankit Agrawal
<ankita@...dia.com>
Subject: Re: [PATCH] dma-buf: fix integer overflow in fill_sg_entry() for
buffers >= 8GiB
On Tue, 25 Nov 2025 17:11:18 -0800
Alex Mastro <amastro@...com> wrote:
> fill_sg_entry() splits large DMA buffers into multiple scatter-gather
> entries, each holding up to UINT_MAX bytes. When calculating the DMA
> address for entries beyond the second one, the expression (i * UINT_MAX)
> causes integer overflow due to 32-bit arithmetic.
>
> This manifests when the input arg length >= 8 GiB results in looping for
> i >= 2.
>
> Fix by casting i to dma_addr_t before multiplication.
>
> Fixes: 3aa31a8bb11e ("dma-buf: provide phys_vec to scatter-gather mapping routine")
> Signed-off-by: Alex Mastro <amastro@...com>
> ---
> More color about how I discovered this in [1] for the commit at [2]:
>
> [1] https://lore.kernel.org/all/aSZHO6otK0Heh+Qj@devgpu015.cco6.facebook.com
> [2] https://lore.kernel.org/all/20251120-dmabuf-vfio-v9-6-d7f71607f371@nvidia.com
> ---
> drivers/dma-buf/dma-buf-mapping.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/dma-buf/dma-buf-mapping.c b/drivers/dma-buf/dma-buf-mapping.c
> index b4819811a64a..b7352e609fbd 100644
> --- a/drivers/dma-buf/dma-buf-mapping.c
> +++ b/drivers/dma-buf/dma-buf-mapping.c
> @@ -24,7 +24,7 @@ static struct scatterlist *fill_sg_entry(struct scatterlist *sgl, size_t length,
> * does not require the CPU list for mapping or unmapping.
> */
> sg_set_page(sgl, NULL, 0, 0);
> - sg_dma_address(sgl) = addr + i * UINT_MAX;
> + sg_dma_address(sgl) = addr + (dma_addr_t)i * UINT_MAX;
> sg_dma_len(sgl) = len;
> sgl = sg_next(sgl);
> }
>
Applied to vfio next branch for v6.19. Thanks,
Alex
Powered by blists - more mailing lists