From: Duoming Zhou <[email protected]>

commit 573601521277119f2e2ba5f28ae6e87fc594f4d4 upstream.

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 <[email protected]>
Reviewed-by: Guenter Roeck <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Guenter Roeck <[email protected]>
Signed-off-by: Wim Van Sebroeck <[email protected]>
[Zhe: Fix for CVE-2024-38630. The function timer_shutdown_sync in the
original fix is not introduced to 5.10 yet. But as stated in f571faf6e443
("timers: Provide timer_shutdown[_sync]()"), "timer_shutdown_sync() has the
same functionality as timer_delete_sync() plus the NULL-ification of the
timer function." So timer_delete_sync is enough for this case.]
Signed-off-by: He Zhe <[email protected]>
---
 drivers/watchdog/cpu5wdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/watchdog/cpu5wdt.c b/drivers/watchdog/cpu5wdt.c
index 9867a3a936df..91adfb55c972 100644
--- a/drivers/watchdog/cpu5wdt.c
+++ b/drivers/watchdog/cpu5wdt.c
@@ -252,7 +252,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);
-- 
2.25.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#14470): 
https://lists.yoctoproject.org/g/linux-yocto/message/14470
Mute This Topic: https://lists.yoctoproject.org/mt/109098340/21656
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to