All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] watchdog: Fix an invalid memory access in 'watchdog_cdev_unregister()'
@ 2021-07-29 16:16 Christophe JAILLET
  2021-07-29 16:27 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2021-07-29 16:16 UTC (permalink / raw)
  To: wim, linux, curtis.klein
  Cc: linux-watchdog, linux-kernel, kernel-janitors, Christophe JAILLET

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.
---
 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);
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] watchdog: Fix an invalid memory access in 'watchdog_cdev_unregister()'
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2021-07-29 16:27 UTC (permalink / raw)
  To: Christophe JAILLET, wim, curtis.klein
  Cc: linux-watchdog, linux-kernel, kernel-janitors

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);
>   }
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-29 16:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.