diff mbox series

[SRU,F,1/1] watchdog: cpu5wdt.c: Fix use-after-free bug caused by cpu5wdt_trigger

Message ID 20240910014409.1052185-2-koichiro.den@canonical.com
State New
Headers show
Series [SRU,F,1/1] watchdog: cpu5wdt.c: Fix use-after-free bug caused by cpu5wdt_trigger | expand

Commit Message

Koichiro Den Sept. 10, 2024, 1:44 a.m. UTC
From: Duoming Zhou <duoming@zju.edu.cn>

When the cpu5wdt module is removing, the origin code uses del_timer() to
de-activate the timer. If the timer handler is running, del_timer() could
not stop it and will return directly. If the port region is released by
release_region() and then the timer handler cpu5wdt_trigger() calls outb()
to write into the region that is released, the use-after-free bug will
happen.

Change del_timer() to timer_shutdown_sync() in order that the timer handler
could be finished before the port region is released.

Fixes: e09d9c3e9f85 ("watchdog: cpu5wdt.c: add missing del_timer call")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/r/20240324140444.119584-1-duoming@zju.edu.cn
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
(backported from commit 573601521277119f2e2ba5f28ae6e87fc594f4d4)
[koichiroden: Adjusted context due to lack of timer_shutdown_sync(),
 which was introduced on upstream in the following patch series:
 [patch V3 00/17] timers: Provide timer_shutdown[_sync]()
 https://lore.kernel.org/all/20221123201306.823305113@linutronix.de/
 Note that part of it was pulled in via stable upstream patches]
CVE-2024-38630
Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
---
 drivers/watchdog/cpu5wdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/watchdog/cpu5wdt.c b/drivers/watchdog/cpu5wdt.c
index d6d53014cb68..02dd22114437 100644
--- a/drivers/watchdog/cpu5wdt.c
+++ b/drivers/watchdog/cpu5wdt.c
@@ -251,7 +251,7 @@  static void cpu5wdt_exit(void)
 	if (cpu5wdt_device.queue) {
 		cpu5wdt_device.queue = 0;
 		wait_for_completion(&cpu5wdt_device.stop);
-		del_timer(&cpu5wdt_device.timer);
+		timer_delete_sync(&cpu5wdt_device.timer);
 	}
 
 	misc_deregister(&cpu5wdt_misc);