mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Artur Kowalski <arturkow2000@gmail.com>,
	Wim Van Sebroeck <wim@linux-watchdog.org>
Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org,
	Wim Van Sebroeck <wim@iguana.be>
Subject: Re: [PATCH] watchdog: core: Fix module refcount imbalance when open fails
Date: Mon, 23 Nov 2026 13:15:52 -0800	[thread overview]
Message-ID: <eafefe7b-c1e2-4130-847c-84b969b471b7@roeck-us.net> (raw)
In-Reply-To: <20261123-core-wdt-fix-v1-1-a315269dce4b@gmail.com>

On 11/23/26 12:46, Artur Kowalski wrote:
> watchdog_open() doesn't take a module reference for a watchdog that is
> running in hardware, as watchdog_cdev_register() already holds one for
> it. If watchdog_start() then fails, which for such a watchdog means the
> driver's ping failed, the error path drops a module reference anyway.
> 
> This drops the reference held for the running watchdog, so the module
> can be unloaded while the watchdog is running and the core still uses
> it. Stopping the watchdog through the core later drops the reference a
> second time, underflowing the module refcount.
> 
> Only drop the module reference on the error path if it was taken.
> 
> This was found with the help of Sashiko and Claude. It can be triggered
> by any modular driver whose ping can fail on a watchdog that was running
> when it was registered. No in-tree driver was checked for that. The fix
> was build tested only, and no reproducer was run.
> 
> Fixes: ee142889e32f ("watchdog: Introduce WDOG_HW_RUNNING flag")
> Signed-off-by: Artur Kowalski <arturkow2000@gmail.com>
> ---
> This was found while developing a Tegra20 watchdog driver. A watchdog
> reset hangs Tegra20's boot ROM once the VDE power partition is off, so
> the driver stops the watchdog behind the core's back when that happens.
> Failing pings afterwards would trigger this bug when opening a watchdog
> left running by the bootloader, so the driver keeps them succeeding
> until user space has started the watchdog.
> ---
>   drivers/watchdog/watchdog_dev.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
> index e8c1fcb53c56..9ad715d4d46d 100644
> --- a/drivers/watchdog/watchdog_dev.c
> +++ b/drivers/watchdog/watchdog_dev.c
> @@ -913,7 +913,8 @@ static int watchdog_open(struct inode *inode, struct file *file)
>   	return stream_open(inode, file);
>   
>   out_mod:
> -	module_put(wd_data->wdd->ops->owner);
> +	if (!hw_running)
> +		module_put(wd_data->wdd->ops->owner);

That seems to be identical to upstream commit e1d91be1ec2e6 ("watchdog:
core: Fix unbalanced module_put() in watchdog_open()").

Id suggest to update your tree to v7.4-rc4 or later to avoid hitting
a number of other recently fixed issues in the watchdog subsystem core.

Thanks,
Guenter


      reply	other threads:[~2026-11-23 21:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 20:46 Artur Kowalski
2026-11-23 21:15 ` Guenter Roeck [this message]

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=eafefe7b-c1e2-4130-847c-84b969b471b7@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=arturkow2000@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=wim@iguana.be \
    --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®