linux-watchdog.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] watchdog: Fix possible use-after-free by calling del_timer_sync()
@ 2021-05-12  6:57 Zou Wei
  2021-05-12 14:06 ` Guenter Roeck
  2021-05-12 17:04 ` Vladimir Zapolskiy
  0 siblings, 2 replies; 4+ messages in thread
From: Zou Wei @ 2021-05-12  6:57 UTC (permalink / raw)
  To: wim, linux, vz; +Cc: linux-watchdog, linux-arm-kernel, linux-kernel, Zou Wei

This driver's remove path calls del_timer(). However, that function
does not wait until the timer handler finishes. This means that the
timer handler may still be running after the driver's remove function
has finished, which would result in a use-after-free.

Fix by calling del_timer_sync(), which makes sure the timer handler
has finished, and unable to re-schedule itself.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zou Wei <zou_wei@huawei.com>
---
 drivers/watchdog/lpc18xx_wdt.c | 2 +-
 drivers/watchdog/w83877f_wdt.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/watchdog/lpc18xx_wdt.c b/drivers/watchdog/lpc18xx_wdt.c
index 78cf11c..60b6d74 100644
--- a/drivers/watchdog/lpc18xx_wdt.c
+++ b/drivers/watchdog/lpc18xx_wdt.c
@@ -292,7 +292,7 @@ static int lpc18xx_wdt_remove(struct platform_device *pdev)
 	struct lpc18xx_wdt_dev *lpc18xx_wdt = platform_get_drvdata(pdev);
 
 	dev_warn(&pdev->dev, "I quit now, hardware will probably reboot!\n");
-	del_timer(&lpc18xx_wdt->timer);
+	del_timer_sync(&lpc18xx_wdt->timer);
 
 	return 0;
 }
diff --git a/drivers/watchdog/w83877f_wdt.c b/drivers/watchdog/w83877f_wdt.c
index 5772cc5..f265086 100644
--- a/drivers/watchdog/w83877f_wdt.c
+++ b/drivers/watchdog/w83877f_wdt.c
@@ -166,7 +166,7 @@ static void wdt_startup(void)
 static void wdt_turnoff(void)
 {
 	/* Stop the timer */
-	del_timer(&timer);
+	del_timer_sync(&timer);
 
 	wdt_change(WDT_DISABLE);
 
-- 
2.6.2


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

* Re: [PATCH -next] watchdog: Fix possible use-after-free by calling del_timer_sync()
  2021-05-12  6:57 [PATCH -next] watchdog: Fix possible use-after-free by calling del_timer_sync() Zou Wei
@ 2021-05-12 14:06 ` Guenter Roeck
  2021-05-13  2:01   ` Samuel Zou
  2021-05-12 17:04 ` Vladimir Zapolskiy
  1 sibling, 1 reply; 4+ messages in thread
From: Guenter Roeck @ 2021-05-12 14:06 UTC (permalink / raw)
  To: Zou Wei; +Cc: wim, vz, linux-watchdog, linux-arm-kernel, linux-kernel

On Wed, May 12, 2021 at 02:57:56PM +0800, Zou Wei wrote:
> This driver's remove path calls del_timer(). However, that function
> does not wait until the timer handler finishes. This means that the
> timer handler may still be running after the driver's remove function
> has finished, which would result in a use-after-free.
> 
> Fix by calling del_timer_sync(), which makes sure the timer handler
> has finished, and unable to re-schedule itself.
> 
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Zou Wei <zou_wei@huawei.com>

If you have more of those, _please_ submit them together to save review time.

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

Guenter

> ---
>  drivers/watchdog/lpc18xx_wdt.c | 2 +-
>  drivers/watchdog/w83877f_wdt.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/watchdog/lpc18xx_wdt.c b/drivers/watchdog/lpc18xx_wdt.c
> index 78cf11c..60b6d74 100644
> --- a/drivers/watchdog/lpc18xx_wdt.c
> +++ b/drivers/watchdog/lpc18xx_wdt.c
> @@ -292,7 +292,7 @@ static int lpc18xx_wdt_remove(struct platform_device *pdev)
>  	struct lpc18xx_wdt_dev *lpc18xx_wdt = platform_get_drvdata(pdev);
>  
>  	dev_warn(&pdev->dev, "I quit now, hardware will probably reboot!\n");
> -	del_timer(&lpc18xx_wdt->timer);
> +	del_timer_sync(&lpc18xx_wdt->timer);
>  
>  	return 0;
>  }
> diff --git a/drivers/watchdog/w83877f_wdt.c b/drivers/watchdog/w83877f_wdt.c
> index 5772cc5..f265086 100644
> --- a/drivers/watchdog/w83877f_wdt.c
> +++ b/drivers/watchdog/w83877f_wdt.c
> @@ -166,7 +166,7 @@ static void wdt_startup(void)
>  static void wdt_turnoff(void)
>  {
>  	/* Stop the timer */
> -	del_timer(&timer);
> +	del_timer_sync(&timer);
>  
>  	wdt_change(WDT_DISABLE);
>  
> -- 
> 2.6.2
> 

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

* Re: [PATCH -next] watchdog: Fix possible use-after-free by calling del_timer_sync()
  2021-05-12  6:57 [PATCH -next] watchdog: Fix possible use-after-free by calling del_timer_sync() Zou Wei
  2021-05-12 14:06 ` Guenter Roeck
@ 2021-05-12 17:04 ` Vladimir Zapolskiy
  1 sibling, 0 replies; 4+ messages in thread
From: Vladimir Zapolskiy @ 2021-05-12 17:04 UTC (permalink / raw)
  To: Zou Wei, wim, linux; +Cc: linux-watchdog, linux-arm-kernel, linux-kernel

On 5/12/21 9:57 AM, Zou Wei wrote:
> This driver's remove path calls del_timer(). However, that function
> does not wait until the timer handler finishes. This means that the
> timer handler may still be running after the driver's remove function
> has finished, which would result in a use-after-free.
> 
> Fix by calling del_timer_sync(), which makes sure the timer handler
> has finished, and unable to re-schedule itself.
> 
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Zou Wei <zou_wei@huawei.com>

Acked-by: Vladimir Zapolskiy <vz@mleia.com>

--
Best wishes,
Vladimir

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

* Re: [PATCH -next] watchdog: Fix possible use-after-free by calling del_timer_sync()
  2021-05-12 14:06 ` Guenter Roeck
@ 2021-05-13  2:01   ` Samuel Zou
  0 siblings, 0 replies; 4+ messages in thread
From: Samuel Zou @ 2021-05-13  2:01 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: wim, vz, linux-watchdog, linux-arm-kernel, linux-kernel

Hi Guenter,

Thanks for your review. If there are similar issues in the future, I 
will collect them together and submit as one patch.

On 2021/5/12 22:06, Guenter Roeck wrote:
> On Wed, May 12, 2021 at 02:57:56PM +0800, Zou Wei wrote:
>> This driver's remove path calls del_timer(). However, that function
>> does not wait until the timer handler finishes. This means that the
>> timer handler may still be running after the driver's remove function
>> has finished, which would result in a use-after-free.
>>
>> Fix by calling del_timer_sync(), which makes sure the timer handler
>> has finished, and unable to re-schedule itself.
>>
>> Reported-by: Hulk Robot <hulkci@huawei.com>
>> Signed-off-by: Zou Wei <zou_wei@huawei.com>
> 
> If you have more of those, _please_ submit them together to save review time.
> 
> Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> 
> Guenter
> >> ---
>>   drivers/watchdog/lpc18xx_wdt.c | 2 +-
>>   drivers/watchdog/w83877f_wdt.c | 2 +-
>>   2 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/watchdog/lpc18xx_wdt.c b/drivers/watchdog/lpc18xx_wdt.c
>> index 78cf11c..60b6d74 100644
>> --- a/drivers/watchdog/lpc18xx_wdt.c
>> +++ b/drivers/watchdog/lpc18xx_wdt.c
>> @@ -292,7 +292,7 @@ static int lpc18xx_wdt_remove(struct platform_device *pdev)
>>   	struct lpc18xx_wdt_dev *lpc18xx_wdt = platform_get_drvdata(pdev);
>>   
>>   	dev_warn(&pdev->dev, "I quit now, hardware will probably reboot!\n");
>> -	del_timer(&lpc18xx_wdt->timer);
>> +	del_timer_sync(&lpc18xx_wdt->timer);
>>   
>>   	return 0;
>>   }
>> diff --git a/drivers/watchdog/w83877f_wdt.c b/drivers/watchdog/w83877f_wdt.c
>> index 5772cc5..f265086 100644
>> --- a/drivers/watchdog/w83877f_wdt.c
>> +++ b/drivers/watchdog/w83877f_wdt.c
>> @@ -166,7 +166,7 @@ static void wdt_startup(void)
>>   static void wdt_turnoff(void)
>>   {
>>   	/* Stop the timer */
>> -	del_timer(&timer);
>> +	del_timer_sync(&timer);
>>   
>>   	wdt_change(WDT_DISABLE);
>>   
>> -- 
>> 2.6.2
>>
> .
> 

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

end of thread, other threads:[~2021-05-13  2:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-12  6:57 [PATCH -next] watchdog: Fix possible use-after-free by calling del_timer_sync() Zou Wei
2021-05-12 14:06 ` Guenter Roeck
2021-05-13  2:01   ` Samuel Zou
2021-05-12 17:04 ` Vladimir Zapolskiy

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).