From: Nhat Tran <nhat.tranminhk2@gmail.com>
To: Wim Van Sebroeck <wim@linux-watchdog.org>,
Guenter Roeck <linux@roeck-us.net>
Cc: Lars Poeschel <poeschel@lemonage.de>,
linux-watchdog@vger.kernel.org, linux-omap@vger.kernel.org,
linux-kernel@vger.kernel.org,
Nhat Tran <nhat.tranminhk2@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH v2] watchdog: core: Don't report time left for a stopped watchdog
Date: Sat, 21 Nov 2026 12:29:50 +0700 [thread overview]
Message-ID: <20261121052950.287506-1-nhat.tranminhk2@gmail.com> (raw)
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@vger.kernel.org
Suggested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Nhat Tran <nhat.tranminhk2@gmail.com>
---
v1->v2:
- Moved the check from omap_wdt into watchdog_get_timeleft(), as
suggested by Guenter, so it covers all drivers
- Return 0 for a stopped watchdog; this also covers WDIOC_GETTIMELEFT
after WDIOS_DISABLECARD on an open device
v1: https://lore.kernel.org/all/20261120124009.24264-1-nhat.tranminhk2@gmail.com/
---
drivers/watchdog/watchdog_dev.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
index e8c1fcb53c56..b67a68316bda 100644
--- a/drivers/watchdog/watchdog_dev.c
+++ b/drivers/watchdog/watchdog_dev.c
@@ -435,6 +435,9 @@ static void watchdog_get_timeleft(struct watchdog_device *wdd,
{
*timeleft = 0;
+ if (!watchdog_active(wdd) && !watchdog_hw_running(wdd))
+ return;
+
if (wdd->ops->get_timeleft) {
*timeleft = wdd->ops->get_timeleft(wdd);
} else {
--
2.25.1
reply other threads:[~2026-11-21 5:30 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261121052950.287506-1-nhat.tranminhk2@gmail.com \
--to=nhat.tranminhk2@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=poeschel@lemonage.de \
--cc=stable@vger.kernel.org \
--cc=wim@linux-watchdog.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®