mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tzung-Bi Shih <tzungbi@kernel.org>
To: Guenter Roeck <linux@roeck-us.net>
Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 6/8] watchdog: core: Cancel timer if cdev_device_add() fails
Date: Wed, 30 Sep 2026 19:54:30 +0800	[thread overview]
Message-ID: <arz4dllgWSG0uIv5@tzungbi-laptop> (raw)
In-Reply-To: <20260929134635.2567137-7-linux@roeck-us.net>

On Tue, Sep 29, 2026 at 06:46:33AM -0700, Guenter Roeck wrote:
> If misc_register() exposed the device to userspace before cdev_device_add()
> is called, a concurrent watchdog_open() could start the watchdog and arm
> wd_data->timer as well as the pretimeout timer. Also, if the hardware
> watchdog was already running, watchdog_open() expects the device and module
> references to have been acquired prior to opening.
> 
> If cdev_device_add() then fails, the error path drops the device reference
> but fails to stop the watchdog, cancel the timers, and stop the worker,
> leaving the watchdog active and timers armed that can later fire and
> dereference freed memory. Furthermore, if a concurrent watchdog_open() saw
> hw_running == true before cdev_device_add() was called, it skipped taking
> its own device reference, allowing put_device() on the error path to free
> wd_data while the file descriptor is still open. Similarly, when
> unregistering a running watchdog that is not currently open, the extra
> hw_running module and device references were never released.
> 
> Fix the problem by initializing wd_data and taking the running-watchdog
> references before exposing the device via misc_register(), stopping the
> watchdog and canceling both the heartbeat and pretimeout timers and
> stopping the worker on registration failure, and releasing unclaimed
> running-watchdog references on registration failure and unregistration.
> 
> Fixes: ee142889e32f ("watchdog: Introduce WDOG_HW_RUNNING flag")
> Assisted-by: LLM
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>

  reply	other threads:[~2026-09-30 11:54 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29 13:46 [PATCH 0/8] watchdog: core: Fix locking, lifetime, suspend, and state management bugs Guenter Roeck
2026-09-29 13:46 ` [PATCH 1/8] watchdog: core: Clear wd_data pointer on errors Guenter Roeck
2026-09-30 11:53   ` Tzung-Bi Shih
2026-09-29 13:46 ` [PATCH 2/8] watchdog: core: Add missing locks Guenter Roeck
2026-09-30 11:53   ` Tzung-Bi Shih
2026-09-29 13:46 ` [PATCH 3/8] watchdog: core: Prevent ping worker from re-arming timer on suspend Guenter Roeck
2026-09-30 11:53   ` Tzung-Bi Shih
2026-09-29 13:46 ` [PATCH 4/8] watchdog: core: Stop pretimeout hrtimer " Guenter Roeck
2026-09-30 11:54   ` Tzung-Bi Shih
2026-09-29 13:46 ` [PATCH 5/8] watchdog: core: Restore WDOG_HW_RUNNING if stopping watchdog fails Guenter Roeck
2026-09-30 11:54   ` Tzung-Bi Shih
2026-09-30 12:37     ` Guenter Roeck
2026-09-29 13:46 ` [PATCH 6/8] watchdog: core: Cancel timer if cdev_device_add() fails Guenter Roeck
2026-09-30 11:54   ` Tzung-Bi Shih [this message]
2026-09-29 13:46 ` [PATCH 7/8] watchdog: core: Fix unbalanced module_put() in watchdog_open() Guenter Roeck
2026-09-30 11:54   ` Tzung-Bi Shih
2026-09-29 13:46 ` [PATCH 8/8] watchdog: core: Update last_keepalive in watchdog_start() Guenter Roeck
2026-09-30 11:54   ` Tzung-Bi Shih

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=arz4dllgWSG0uIv5@tzungbi-laptop \
    --to=tzungbi@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    /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®