public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] iio: at91-sama5d2_adc: Fix use after free bug in at91_adc_remove due to race condition
@ 2023-03-10  9:12 Zheng Wang
  2023-03-18 17:39 ` Jonathan Cameron
  2023-03-20  9:35 ` Nicolas Ferre
  0 siblings, 2 replies; 9+ messages in thread
From: Zheng Wang @ 2023-03-10  9:12 UTC (permalink / raw)
  To: eugen.hristev
  Cc: alexandre.belloni, lars, linux-iio, linux-kernel,
	linux-arm-kernel, Zheng Wang, claudiu.beznea, jic23

In at91_adc_probe, &st->touch_st.workq is bound with
at91_adc_workq_handler. Then it will be started by irq
handler at91_adc_touch_data_handler

If we remove the driver which will call at91_adc_remove
  to make cleanup, there may be a unfinished work.

The possible sequence is as follows:

Fix it by finishing the work before cleanup in the at91_adc_remove

CPU0                  CPU1

                    |at91_adc_workq_handler
at91_adc_remove     |
iio_device_unregister|
iio_dev_release     |
kfree(iio_dev_opaque);|
                    |
                    |iio_push_to_buffers
                    |&iio_dev_opaque->buffer_list
                    |//use
Fixes: 23ec2774f1cc ("iio: adc: at91-sama5d2_adc: add support for position and pressure channels")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
 drivers/iio/adc/at91-sama5d2_adc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c
index 50d02e5fc6fc..1b95d18d9e0b 100644
--- a/drivers/iio/adc/at91-sama5d2_adc.c
+++ b/drivers/iio/adc/at91-sama5d2_adc.c
@@ -2495,6 +2495,8 @@ static int at91_adc_remove(struct platform_device *pdev)
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
 	struct at91_adc_state *st = iio_priv(indio_dev);
 
+	disable_irq_nosync(st->irq);
+	cancel_work_sync(&st->touch_st.workq);
 	iio_device_unregister(indio_dev);
 
 	at91_adc_dma_disable(st);
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2023-03-20 12:09 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-10  9:12 [PATCH] iio: at91-sama5d2_adc: Fix use after free bug in at91_adc_remove due to race condition Zheng Wang
2023-03-18 17:39 ` Jonathan Cameron
2023-03-18 17:36   ` Lars-Peter Clausen
2023-03-19 15:22     ` Jonathan Cameron
2023-03-20  3:54       ` 王征
2023-03-20  3:41     ` 王征
2023-03-20  3:40   ` 王征
2023-03-20  9:35 ` Nicolas Ferre
2023-03-20 12:07   ` 王征

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