* [PATCH] watchdog: omap: Do not read the counter while the watchdog is stopped
@ 2026-11-20 12:40 Nhat Tran
0 siblings, 0 replies; only message in thread
From: Nhat Tran @ 2026-11-20 12:40 UTC (permalink / raw)
To: Wim Van Sebroeck, Guenter Roeck
Cc: linux-watchdog, linux-omap, linux-kernel, Nhat Tran, stable
omap_wdt only holds a runtime PM reference between omap_wdt_start() and
omap_wdt_stop(), so the module is idle and its clock gated whenever the
watchdog is not running. omap_wdt_get_timeleft() reads the WCRR register
unconditionally, but the watchdog core calls ->get_timeleft() from the
sysfs timeleft attribute without checking whether the watchdog is
active.
With CONFIG_WATCHDOG_SYSFS=y the attribute is world readable, so any
unprivileged user can trigger an external abort on a stopped watchdog.
On a BeagleBone Black (AM335x), with panic_on_oops set:
$ id
uid=1000(tester) gid=1000(tester) groups=1000(tester)
$ cat /sys/class/watchdog/watchdog0/timeleft
Unhandled fault: external abort on non-linefetch (0x1028) at 0xf9e35028
Internal error: : 1028 [#1] SMP ARM
CPU: 0 UID: 1000 PID: 239 Comm: cat Not tainted 7.4.0-rc2-00716-g23c62304dde2-dirty #10 VOLUNTARY
Hardware name: Generic AM33XX (Flattened Device Tree)
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
sysfs_kf_seq_show from seq_read_iter+0x194/0x4c0
seq_read_iter from copy_splice_read+0x168/0x2d8
copy_splice_read from splice_direct_to_actor+0xb4/0x2b4
splice_direct_to_actor from do_splice_direct_actor+0x84/0xcc
do_splice_direct_actor from do_splice_direct+0x24/0x30
do_splice_direct from do_sendfile+0x2fc/0x3a4
do_sendfile from sys_sendfile64+0x10c/0x128
sys_sendfile64 from ret_fast_syscall+0x0/0x54
Kernel panic - not syncing: Fatal exception
Only read the counter while the watchdog is running, under wdev->lock
so the check cannot race with start() and stop(), and report 0 time
left otherwise.
Tested on a BeagleBone Black: with the watchdog stopped, timeleft now
reads 0 for an unprivileged user; with the watchdog started through
/dev/watchdog it counts down as before.
Fixes: 452fafed839e ("watchdog: omap_wdt: implement get_timeleft")
Cc: stable@vger.kernel.org
Signed-off-by: Nhat Tran <nhat.tranminhk2@gmail.com>
---
drivers/watchdog/omap_wdt.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/watchdog/omap_wdt.c b/drivers/watchdog/omap_wdt.c
index c60bc678262c..82e50244176f 100644
--- a/drivers/watchdog/omap_wdt.c
+++ b/drivers/watchdog/omap_wdt.c
@@ -206,10 +206,14 @@ static unsigned int omap_wdt_get_timeleft(struct watchdog_device *wdog)
{
struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
void __iomem *base = wdev->base;
- u32 value;
+ unsigned int timeleft = 0;
- value = readl_relaxed(base + OMAP_WATCHDOG_CRR);
- return GET_WCCR_SECS(value);
+ mutex_lock(&wdev->lock);
+ if (wdev->omap_wdt_users)
+ timeleft = GET_WCCR_SECS(readl_relaxed(base + OMAP_WATCHDOG_CRR));
+ mutex_unlock(&wdev->lock);
+
+ return timeleft;
}
static const struct watchdog_info omap_wdt_info = {
--
2.25.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-20 12:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 12:40 [PATCH] watchdog: omap: Do not read the counter while the watchdog is stopped Nhat Tran
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®