Re: [PATCH v2] watchdog: core: Don't report time left for a stopped watchdog
From: Guenter Roeck
Date: Sat Nov 21 2026 - 10:26:19 EST
On Sat, Nov 21, 2026 at 12:29:50PM +0700, Nhat Tran wrote:
> watchdog_get_timeleft() calls the driver's ->get_timeleft() regardless
> of whether the watchdog is running. It is reachable through the sysfs
> timeleft attribute, which is world readable with CONFIG_WATCHDOG_SYSFS=y,
> and through WDIOC_GETTIMELEFT, also after the watchdog was stopped with
> WDIOS_DISABLECARD while the device is still open.
>
> Drivers may not be able to access the hardware while the watchdog is
> stopped. omap_wdt only holds a runtime PM reference while the watchdog
> is running, so on a BeagleBone Black (AM335x) reading the counter of a
> stopped watchdog triggers an external abort. Any unprivileged user can
> hit it through sysfs:
>
> $ cat /sys/class/watchdog/watchdog0/timeleft
> Unhandled fault: external abort on non-linefetch (0x1028) at 0xf9e35028
> Internal error: : 1028 [#1] SMP ARM
> PC is at omap_wdt_get_timeleft+0x4/0x14
> LR is at watchdog_get_timeleft+0x24/0x130
> Call trace:
> omap_wdt_get_timeleft from watchdog_get_timeleft+0x24/0x130
> watchdog_get_timeleft from timeleft_show+0x3c/0x80
> timeleft_show from dev_attr_show+0x18/0x4c
> dev_attr_show from sysfs_kf_seq_show+0xa0/0x138
> ...
>
> and the same happens with WDIOS_DISABLECARD followed by
> WDIOC_GETTIMELEFT on the open device, once the module has idled:
>
> Call trace:
> omap_wdt_get_timeleft from watchdog_get_timeleft+0x24/0x130
> watchdog_get_timeleft from watchdog_ioctl+0x494/0x668
> watchdog_ioctl from sys_ioctl+0x128/0xbcc
> sys_ioctl from ret_fast_syscall+0x0/0x54
>
> If the ioctl comes before the module has idled, the read succeeds but
> reports 59 seconds left for a watchdog that is stopped.
>
> A stopped watchdog will not reboot the system, so report 0 time left
> when neither WDOG_ACTIVE nor WDOG_HW_RUNNING is set, without calling
> into the driver. This matches the software fallback for drivers without
> ->get_timeleft(), which already decays to 0 once the watchdog is no
> longer pinged.
>
> Tested on a BeagleBone Black: with the watchdog stopped, both the sysfs
> attribute and WDIOC_GETTIMELEFT after WDIOS_DISABLECARD return 0; with
> the watchdog started through /dev/watchdog0, timeleft counts down as
> before (59, then 56 three seconds later).
>
> Fixes: 452fafed839e ("watchdog: omap_wdt: implement get_timeleft")
> Cc: stable@xxxxxxxxxxxxxxx
> Suggested-by: Guenter Roeck <linux@xxxxxxxxxxxx>
> Signed-off-by: Nhat Tran <nhat.tranminhk2@xxxxxxxxx>
Applied, and thanks for testing with WDIOS_DISABLECARD/WDIOC_GETTIMELEFT.
Thanks,
Guenter