mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] iio: adc: ti_am335x_adc: Fix potential use-after-free on DMA unbind
@ 2026-11-24 13:58 Guangshuo Li
  2026-11-28 19:59 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-11-24 13:58 UTC (permalink / raw)
  To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko
  Cc: linux-iio, linux-kernel, stable, Andy Shevchenko

A channel reference does not keep the DMA provider bound. If the EDMA
provider is unbound first, ADC removal accesses the freed channel when
freeing its DMA buffer and releasing the channel.

Link the ADC platform device to the provider so the ADC is removed first,
including when firmware device links are disabled. The driver core drops
the link on probe failure or ADC removal.

This issue was found by our static analysis tool under development.

Fixes: f438b9da75eb ("drivers: iio: ti_am335x_adc: add dma support")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
Changes in v2:
  - Use dmaengine_get_provider_device() to obtain the supplier device.

  Backports need 61527d7e6998 ("dmaengine: add dmaengine_get_provider_device() API").

 drivers/iio/adc/ti_am335x_adc.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index 0c3e0e9e8364..c7f8bafe0f4a 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -546,6 +546,11 @@ static int tiadc_request_dma(struct platform_device *pdev,
 		return ret;
 	}
 
+	if (!device_link_add(&pdev->dev,
+			     dmaengine_get_provider_device(dma->chan),
+			     DL_FLAG_AUTOREMOVE_CONSUMER))
+		goto err;
+
 	/* RX buffer */
 	dma->buf = dma_alloc_coherent(dmaengine_get_dma_device(dma->chan), DMA_BUFFER_SIZE,
 				      &dma->addr, GFP_KERNEL);

base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] iio: adc: ti_am335x_adc: Fix potential use-after-free on DMA unbind
  2026-11-24 13:58 [PATCH v2] iio: adc: ti_am335x_adc: Fix potential use-after-free on DMA unbind Guangshuo Li
@ 2026-11-28 19:59 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2026-11-28 19:59 UTC (permalink / raw)
  To: Guangshuo Li
  Cc: David Lechner, Nuno Sá,
	Andy Shevchenko, linux-iio, linux-kernel, stable,
	Andy Shevchenko

On Tue, 24 Nov 2026 21:58:28 +0800
Guangshuo Li <liguangshuo@mail.sdu.edu.cn> wrote:

> A channel reference does not keep the DMA provider bound. If the EDMA
> provider is unbound first, ADC removal accesses the freed channel when
> freeing its DMA buffer and releasing the channel.
> 
> Link the ADC platform device to the provider so the ADC is removed first,
> including when firmware device links are disabled. The driver core drops
> the link on probe failure or ADC removal.
> 
> This issue was found by our static analysis tool under development.
> 
> Fixes: f438b9da75eb ("drivers: iio: ti_am335x_adc: add dma support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
From the sashiko review of patch 1 there may be other gremlins hiding 
in this driver.  This seems ok though.

Applied to the testing branch of iio.git. So lined up for next merge window
rather than rushing it in.

Jonathan


> ---
> Changes in v2:
>   - Use dmaengine_get_provider_device() to obtain the supplier device.
> 
>   Backports need 61527d7e6998 ("dmaengine: add dmaengine_get_provider_device() API").
> 
>  drivers/iio/adc/ti_am335x_adc.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
> index 0c3e0e9e8364..c7f8bafe0f4a 100644
> --- a/drivers/iio/adc/ti_am335x_adc.c
> +++ b/drivers/iio/adc/ti_am335x_adc.c
> @@ -546,6 +546,11 @@ static int tiadc_request_dma(struct platform_device *pdev,
>  		return ret;
>  	}
>  
> +	if (!device_link_add(&pdev->dev,
> +			     dmaengine_get_provider_device(dma->chan),
> +			     DL_FLAG_AUTOREMOVE_CONSUMER))
> +		goto err;
> +
>  	/* RX buffer */
>  	dma->buf = dma_alloc_coherent(dmaengine_get_dma_device(dma->chan), DMA_BUFFER_SIZE,
>  				      &dma->addr, GFP_KERNEL);
> 
> base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-28 19:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 13:58 [PATCH v2] iio: adc: ti_am335x_adc: Fix potential use-after-free on DMA unbind Guangshuo Li
2026-11-28 19:59 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®