All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Baoquan He" <hebaoquan@kylinos.cn>
Cc: Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH 10/13] media: imx7-media-csi: Don't use GFP_DMA when calling dma_alloc_coherent()
Date: Thu, 03 Sep 2026 11:36:28 +0000	[thread overview]
Message-ID: <20260903113629.1D3221F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260903111836.1777265-11-hebaoquan@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Integer overflow in `sizeimage` calculation and signedness truncation in `imx7_csi_alloc_dma_buf()` allow userspace to trigger a massive out-of-bounds DMA write, corrupting kernel memory.
--

commit 007baffc77bd7059db343099782a06610465cf12
Author: Baoquan He <hebaoquan@kylinos.cn>
Subject: media: imx7-media-csi: Don't use GFP_DMA when calling dma_alloc_coherent()

This commit removes the redundant GFP_DMA flag from the dma_alloc_coherent()
call in imx7_csi_alloc_dma_buf(). The DMA core already handles device
addressing limitations and ignores GFP_DMA.

> diff --git a/drivers/media/platform/nxp/imx7-media-csi.c b/drivers/media/platform/nxp/imx7-media-csi.c
> index 7ddc7ba06e3d4..22c0cbdc92bfb 100644
> --- a/drivers/media/platform/nxp/imx7-media-csi.c
> +++ b/drivers/media/platform/nxp/imx7-media-csi.c
> @@ -466,7 +466,7 @@ static int imx7_csi_alloc_dma_buf(struct imx7_csi *csi,
>  
>  	buf->len = PAGE_ALIGN(size);
>  	buf->virt = dma_alloc_coherent(csi->dev, buf->len, &buf->dma_addr,
> -				       GFP_DMA | GFP_KERNEL);
> +				       GFP_KERNEL);
[Severity: Critical]
This isn't a bug introduced by this patch, but could this allocation lead to
arbitrary kernel memory corruption?

The size parameter in imx7_csi_alloc_dma_buf() is a signed int. This allows
large unsigned 32-bit sizeimage values (e.g., between 2 GB and 4 GB) to be
interpreted as negative, subverting the PAGE_ALIGN macro.

This seems to be reachable from userspace because imx7_csi_try_fmt() lacks
bounds checking for width and height in the IMX7_CSI_PAD_SINK case:

drivers/media/platform/nxp/imx7-media-csi.c:imx7_csi_try_fmt() {
    ...
    case IMX7_CSI_PAD_SINK:
        *cc = imx7_csi_find_mbus_format(sdformat->format.code);
    ...
}

This allows massive dimensions to bypass validation. When passed to
__imx7_csi_video_try_fmt(), the 32-bit multiplication overflows without
prior bounds checking on the total pixel volume:

drivers/media/platform/nxp/imx7-media-csi.c:__imx7_csi_video_try_fmt() {
    ...
    pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;
    ...
}

If a user calls VIDIOC_S_FMT with large dimensions (e.g., width=32896,
height=65281, and a 16-bpp format), the product wraps around modulo 2^32,
producing a very small positive sizeimage, or a negative size when passed
as a signed int to imx7_csi_alloc_dma_buf().

As a result, a tiny buffer is allocated here, but the CSI hardware could
capture the massive frame and DMA up to 4 GB of data into it, seamlessly
crossing the buffer boundary.

>  	if (!buf->virt)
>  		return -ENOMEM;
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260903111836.1777265-1-hebaoquan@kylinos.cn?part=10

  reply	other threads:[~2026-09-03 11:36 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-03 11:18 [PATCH 00/13] Don't use GFP_DMA when calling dma_alloc_coherent Baoquan He
2026-09-03 11:18 ` [PATCH 01/13] gpu: ipu-v3: Don't use GFP_DMA when calling dma_alloc_coherent() Baoquan He
2026-09-03 11:18 ` [PATCH 02/13] drm/sti: Don't use GFP_DMA when calling dma_alloc_wc() Baoquan He
2026-09-03 11:29   ` sashiko-bot
2026-09-03 11:18 ` [PATCH 03/13] ALSA: n64: Don't use GFP_DMA when calling dma_alloc_coherent() Baoquan He
2026-09-03 11:18 ` [PATCH 04/13] spi: spi-ti-qspi: " Baoquan He
2026-09-03 11:18 ` [PATCH 05/13] fbdev: fsl-diu-fb: Don't use GFP_DMA when calling dmam_alloc_coherent() Baoquan He
2026-09-03 11:30   ` sashiko-bot
2026-09-03 11:18 ` [PATCH 06/13] usb: gadget: lpc32xx_udc: Don't use GFP_DMA when calling dma_alloc_coherent() Baoquan He
2026-09-03 11:18 ` [PATCH 07/13] usb: cdns3: " Baoquan He
2026-09-03 11:18 ` [PATCH 08/13] media: staging: imx: " Baoquan He
2026-09-03 11:18 ` [PATCH 09/13] spi: atmel: " Baoquan He
2026-09-03 11:18 ` [PATCH 10/13] media: imx7-media-csi: " Baoquan He
2026-09-03 11:36   ` sashiko-bot [this message]
2026-09-04 15:14   ` Frank Li
2026-09-03 11:18 ` [PATCH 11/13] media: nxp: imx8-isi: " Baoquan He
2026-09-03 11:37   ` sashiko-bot
2026-09-04 15:14   ` Frank Li
2026-09-03 11:18 ` [PATCH 12/13] mtd: rawnand: gpmi: " Baoquan He
2026-09-03 11:18   ` Baoquan He
2026-09-03 11:18 ` [PATCH 13/13] usb: cdns2: " Baoquan He

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=20260903113629.1D3221F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=hebaoquan@kylinos.cn \
    --cc=imx@lists.linux.dev \
    --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.