Skip to contentSkip to conversation

watchdog: Fix possible use-after-free by calling del_timer_sync()

PATCH In review Zou Wei 3 participants 4 messages May 12, 2021 – May 13, 2021

Subsystems (2)
lore
Share & tools
lore

Zou Wei

author
#0 lore raw

PATCH 1/1 watchdog: Fix possible use-after-free by calling del_timer_sync()

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.

---
 drivers/watchdog/lpc18xx_wdt.c | 2 +-
 drivers/watchdog/w83877f_wdt.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/watchdog/lpc18xx_wdt.c +1 -1
index 78cf11c..60b6d74 100644
@@ -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;
 }
drivers/watchdog/w83877f_wdt.c +1 -1
index 5772cc5..f265086 100644
@@ -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);
 
Signature · 1 line
2.6.2
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · 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.

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

Guenter

Quoted 34 lines
---
 drivers/watchdog/lpc18xx_wdt.c | 2 +-
 drivers/watchdog/w83877f_wdt.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/watchdog/lpc18xx_wdt.c +1 -1
index 78cf11c..60b6d74 100644
@@ -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;
 }
drivers/watchdog/w83877f_wdt.c +1 -1
index 5772cc5..f265086 100644
@@ -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);
 
Signature · 1 line
2.6.2
author
#2 lore raw

Hi Guenter,

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

Quoted 53 lines · Guenter Roeck
Quoted 10 lines · 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.

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

Guenter

Quoted 34 lines
Quoted 1 line

---

  drivers/watchdog/lpc18xx_wdt.c | 2 +-
  drivers/watchdog/w83877f_wdt.c | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
drivers/watchdog/lpc18xx_wdt.c +1 -1
index 78cf11c..60b6d74 100644
@@ -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;
  }
drivers/watchdog/w83877f_wdt.c +1 -1
index 5772cc5..f265086 100644
@@ -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);
 
Signature · 1 line
2.6.2

.

maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Zou Wei
Quoted 10 lines · 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.

--
Best wishes,
Vladimir

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel