From: Frank Li <Frank.li@nxp.com>
To: John Madieu <john.madieu@gmail.com>
Cc: broonie@kernel.org, s.hauer@pengutronix.de,
kernel@pengutronix.de, festevam@gmail.com, carlos.song@nxp.com,
linux-spi@vger.kernel.org, imx@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] spi: imx: Fix UAF on package-1 prepare failure in spi_imx_dma_data_prepare()
Date: Sat, 2 May 2026 00:49:33 -0400 [thread overview]
Message-ID: <afWCXTn_x6HtjNZa@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20260501135951.2416527-3-john.madieu@gmail.com>
On Fri, May 01, 2026 at 01:59:50PM +0000, John Madieu wrote:
> When transfer->len exceeds MX51_ECSPI_CTRL_MAX_BURST and is not a
> multiple of it, spi_imx_dma_data_prepare() splits the transfer into
> two DMA packages. If preparing the second package fails:
>
> ret = spi_imx_dma_tx_data_handle(spi_imx, &spi_imx->dma_data[1],
> transfer->tx_buf + spi_imx->dma_data[0].data_len,
> false);
> if (ret) {
> kfree(spi_imx->dma_data[0].dma_tx_buf);
> kfree(spi_imx->dma_data[0].dma_rx_buf);
> kfree(spi_imx->dma_data);
> }
> }
Nit: duplicated }
>
> return 0;
>
> the function frees the package-0 buffers and the dma_data array,
> then falls through to `return 0`, telling the caller the prepare
> succeeded. The caller then dereferences the freed dma_data array,
> producing a use-after-free.
>
> Return the error from the failure path so the caller takes its
> existing failure branch.
>
> Fixes: faa8e404ad8e ("spi: imx: support dynamic burst length for ECSPI DMA mode")
> Signed-off-by: John Madieu <john.madieu@gmail.com>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> drivers/spi/spi-imx.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
> index 7ae8078c10ef..4e3dbd01d619 100644
> --- a/drivers/spi/spi-imx.c
> +++ b/drivers/spi/spi-imx.c
> @@ -1709,6 +1709,7 @@ static int spi_imx_dma_data_prepare(struct spi_imx_data *spi_imx,
> kfree(spi_imx->dma_data[0].dma_tx_buf);
> kfree(spi_imx->dma_data[0].dma_rx_buf);
> kfree(spi_imx->dma_data);
> + return ret;
> }
> }
>
> --
> 2.25.1
>
next prev parent reply other threads:[~2026-05-02 4:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-01 13:59 [PATCH 0/3] spi: imx: Three fixes for the i.MX SPI driver John Madieu
2026-05-01 13:59 ` [PATCH 1/3] spi: imx: Fix precedence bug in spi_imx_dma_max_wml_find() John Madieu
2026-05-02 4:46 ` Frank Li
2026-05-01 13:59 ` [PATCH 2/3] spi: imx: Fix UAF on package-1 prepare failure in spi_imx_dma_data_prepare() John Madieu
2026-05-02 4:49 ` Frank Li [this message]
2026-05-01 13:59 ` [PATCH 3/3] spi: imx: Propagate prepare_transfer() error from spi_imx_setupxfer() John Madieu
2026-05-02 4:51 ` Frank Li
2026-05-04 13:22 ` [PATCH 0/3] spi: imx: Three fixes for the i.MX SPI driver Mark Brown
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=afWCXTn_x6HtjNZa@lizhi-Precision-Tower-5810 \
--to=frank.li@nxp.com \
--cc=broonie@kernel.org \
--cc=carlos.song@nxp.com \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=john.madieu@gmail.com \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=s.hauer@pengutronix.de \
/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