From: Guenter Roeck <linux@roeck-us.net>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
wim@linux-watchdog.org, curtis.klein@hpe.com
Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] watchdog: Fix an invalid memory access in 'watchdog_cdev_unregister()'
Date: Thu, 29 Jul 2021 09:27:31 -0700 [thread overview]
Message-ID: <af32d970-b96e-724b-7f5e-c9544f8aee6a@roeck-us.net> (raw)
In-Reply-To: <dcb65e66acd1a50d65635b35d0d340846c7d10c7.1627575359.git.christophe.jaillet@wanadoo.fr>
On 7/29/21 9:16 AM, Christophe JAILLET wrote:
> A few lines before 'watchdog_hrtimer_pretimeout_stop(wdd)', we explicitly
> set 'wdd->wd_data' to NULL.
> So, it is more than likely than this call will lead to an invalid
> memory access.
>
> Move this call before the 'wdd->wd_data = NULL;'
>
> Fixes: 7b7d2fdc8c3e ("watchdog: Add hrtimer-based pretimeout feature")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Completely untested!
> Not sure at all, that it is the way to fix it.
Nice catch. Should be ok.
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> ---
> 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 3bab32485273..ffd8f1a82355 100644
> --- a/drivers/watchdog/watchdog_dev.c
> +++ b/drivers/watchdog/watchdog_dev.c
> @@ -1096,6 +1096,8 @@ static void watchdog_cdev_unregister(struct watchdog_device *wdd)
> watchdog_stop(wdd);
> }
>
> + watchdog_hrtimer_pretimeout_stop(wdd);
> +
> mutex_lock(&wd_data->lock);
> wd_data->wdd = NULL;
> wdd->wd_data = NULL;
> @@ -1103,7 +1105,6 @@ static void watchdog_cdev_unregister(struct watchdog_device *wdd)
>
> hrtimer_cancel(&wd_data->timer);
> kthread_cancel_work_sync(&wd_data->work);
> - watchdog_hrtimer_pretimeout_stop(wdd);
>
> put_device(&wd_data->dev);
> }
>
prev parent reply other threads:[~2021-07-29 16:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-29 16:16 [PATCH] watchdog: Fix an invalid memory access in 'watchdog_cdev_unregister()' Christophe JAILLET
2021-07-29 16:27 ` 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=af32d970-b96e-724b-7f5e-c9544f8aee6a@roeck-us.net \
--to=linux@roeck-us.net \
--cc=christophe.jaillet@wanadoo.fr \
--cc=curtis.klein@hpe.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-watchdog@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;
as well as URLs for NNTP newsgroup(s).