linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: 王征 <zyytlz.wz@163.com>
To: "Nicolas Ferre" <nicolas.ferre@microchip.com>
Cc: eugen.hristev@collabora.com, jic23@kernel.org, lars@metafoo.de,
	alexandre.belloni@bootlin.com, claudiu.beznea@microchip.com,
	linux-iio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, hackerzheng666@gmail.com,
	1395428693sheep@gmail.com, alex000young@gmail.com
Subject: Re:Re: [PATCH] iio: at91-sama5d2_adc: Fix use after free bug in at91_adc_remove due to race condition
Date: Mon, 20 Mar 2023 20:07:52 +0800 (CST)	[thread overview]
Message-ID: <2220fb68.10ff7.186feeb3231.Coremail.zyytlz.wz@163.com> (raw)
In-Reply-To: <954acc8c-0df3-23a4-7237-ecbc31811a56@microchip.com>

















At 2023-03-20 16:35:24, "Nicolas Ferre" <nicolas.ferre@microchip.com> wrote:
>On 10/03/2023 at 10:12, Zheng Wang wrote:
>> 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
>
>There is no such thing as a SMP platform using this driver (yet?), so we 
>agree that this fix is purely theoretical, cannot be reproduced nor its 
>fix validated.
>
>That being said, I'm happy that enhancements are provided to this 
>driver, no doubt about that.
>

Hi Nicolas,

Thanks for your reply. I'm not familiar with the module and I think you're right.

>
>> 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);
>
>About stopping the source of interrupt, I would recommend using a 
>sequence already exposed in at91_adc_hw_init (and possibly make it 
>common), like:
>
>    if (st->soc_info.platform->layout->EOC_IDR)
>            at91_adc_writel(st, EOC_IDR, 0xffffffff);
>    at91_adc_writel(st, IDR, 0xffffffff);
>

Thanks fou your advice. I'll apply it in the next version.

Best regards,
Zheng

>Regards,
>   Nicolas
>
>>          iio_device_unregister(indio_dev);
>> 
>>          at91_adc_dma_disable(st);
>> --
>> 2.25.1
>> 
>
>-- 
>Nicolas Ferre

      reply	other threads:[~2023-03-20 12:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

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=2220fb68.10ff7.186feeb3231.Coremail.zyytlz.wz@163.com \
    --to=zyytlz.wz@163.com \
    --cc=1395428693sheep@gmail.com \
    --cc=alex000young@gmail.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=claudiu.beznea@microchip.com \
    --cc=eugen.hristev@collabora.com \
    --cc=hackerzheng666@gmail.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    /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;
as well as URLs for NNTP newsgroup(s).