Linux Watchdog driver development
 help / color / mirror / Atom feed
* [PATCH] watchdog: airoha: validate heartbeat module parameter
@ 2026-07-08  5:24 Wayen Yan
  2026-07-08  5:36 ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: Wayen Yan @ 2026-07-08  5:24 UTC (permalink / raw)
  To: Wim Van Sebroeck
  Cc: Guenter Roeck, Christian Marangi, linux-watchdog, linux-kernel

The probe function directly assigns the heartbeat module parameter to
wdog_dev->timeout without any validation. If heartbeat exceeds
max_timeout, the product timeout * wdt_freq (computed in
airoha_wdt_start()) can overflow the 32-bit WDT_TIMER_LOAD_VALUE
register, causing the watchdog to expire immediately and reboot the
system.

Fix by using watchdog_init_timeout() which validates the timeout
against [min_timeout, max_timeout] range, and falls back to the
device tree "timeout-sec" property if the module parameter is invalid.

Fixes: 3cf67f3769b8 ("watchdog: Add support for Airoha EN7851 watchdog")
Signed-off-by: Wayen Yan <win847@gmail.com>
---
 drivers/watchdog/airoha_wdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/watchdog/airoha_wdt.c b/drivers/watchdog/airoha_wdt.c
index dc8ca11c14d8..67160d760d84 100644
--- a/drivers/watchdog/airoha_wdt.c
+++ b/drivers/watchdog/airoha_wdt.c
@@ -150,13 +150,13 @@ static int airoha_wdt_probe(struct platform_device *pdev)
 
 	/* Initialize struct watchdog device */
 	wdog_dev = &airoha_wdt->wdog_dev;
-	wdog_dev->timeout = heartbeat;
 	wdog_dev->info = &airoha_wdt_info;
 	wdog_dev->ops = &airoha_wdt_ops;
 	/* Bus 300MHz, watchdog 150MHz, 28 seconds */
 	wdog_dev->max_timeout = FIELD_MAX(WDT_TIMER_VAL) / airoha_wdt->wdt_freq;
 	wdog_dev->parent = dev;
 
+	watchdog_init_timeout(wdog_dev, heartbeat, dev);
 	watchdog_set_drvdata(wdog_dev, airoha_wdt);
 	watchdog_set_nowayout(wdog_dev, nowayout);
 	watchdog_stop_on_unregister(wdog_dev);
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread
* Re: [PATCH] watchdog: airoha: validate heartbeat module parameter
@ 2026-07-08  5:55 Wayen Yan
  0 siblings, 0 replies; 3+ messages in thread
From: Wayen Yan @ 2026-07-08  5:55 UTC (permalink / raw)
  To: linux-watchdog
  Cc: Wim Van Sebroeck, Guenter Roeck, Christian Marangi, linux-kernel

Please do not apply the above patch. It introduces a regression:

The patch removes the direct assignment "wdog_dev->timeout = heartbeat"
and relies on watchdog_init_timeout() instead. However, since wdog_dev
is allocated via devm_kzalloc(), timeout is initialized to 0. If the
heartbeat module parameter is invalid and there is no "timeout-sec" DT
property, watchdog_init_timeout() returns -EINVAL and leaves timeout
at 0. When the watchdog is subsequently started, airoha_wdt_start()
writes 0 * wdt_freq = 0 to WDT_TIMER_LOAD_VALUE, causing an immediate
hardware reboot — which is worse than the original overflow bug.

I will send a v2 patch that:
1. Pre-initializes timeout to WDT_HEARTBEAT before calling
   watchdog_init_timeout(), so the safe default is preserved on failure
2. Sets min_timeout = 1 to prevent timeout = 0 via ioctl

Sorry for the noise.

Wayen


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

end of thread, other threads:[~2026-07-08  5:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08  5:24 [PATCH] watchdog: airoha: validate heartbeat module parameter Wayen Yan
2026-07-08  5:36 ` sashiko-bot
  -- strict thread matches above, loose matches on Subject: below --
2026-07-08  5:55 Wayen Yan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox