From: Nhat Tran <nhat.tranminhk2@gmail.com>
To: Wim Van Sebroeck <wim@linux-watchdog.org>,
Guenter Roeck <linux@roeck-us.net>
Cc: 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] watchdog: omap: Do not read the counter while the watchdog is stopped
Date: Fri, 20 Nov 2026 19:40:09 +0700 [thread overview]
Message-ID: <20261120124009.24264-1-nhat.tranminhk2@gmail.com> (raw)
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
reply other threads:[~2026-11-20 12:40 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=20261120124009.24264-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=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®