mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fanotify: stop permission watchdog when timeout is zero
@ 2026-07-30  7:06 Yichong Chen
  2026-07-30  9:55 ` Jan Kara
  0 siblings, 1 reply; 2+ messages in thread
From: Yichong Chen @ 2026-07-30  7:06 UTC (permalink / raw)
  To: jack
  Cc: amir73il, repnop, mszeredi, linux-fsdevel, linux-kernel, Yichong Chen

The fanotify permission watchdog can be disabled by writing zero to
fs/fanotify/watchdog_timeout.  fanotify_perm_watchdog_group_add() already
checks for a zero timeout before scheduling the watchdog.

However, once the watchdog work has been scheduled, perm_group_watchdog()
unconditionally schedules itself again with the current timeout.  If the
sysctl is changed to zero while the work is active, secs_to_jiffies(0)
causes the work to be rescheduled immediately, resulting in a kworker
busy loop.

Read the timeout once in perm_group_watchdog_schedule() and do not
schedule the work when it is zero.  This lets a running watchdog stop
after the next execution when the sysctl is set to zero.

Fixes: b8cf8fda522d ("fanotify: add watchdog for permission events")
Signed-off-by: Yichong Chen <chenyichong@uniontech.com>
---
 fs/notify/fanotify/fanotify_user.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index b604e3da58ad..9ee373ff5840 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -112,7 +112,12 @@ static DECLARE_DELAYED_WORK(perm_group_work, perm_group_watchdog);
 
 static void perm_group_watchdog_schedule(void)
 {
-	schedule_delayed_work(&perm_group_work, secs_to_jiffies(perm_group_timeout));
+	int timeout = READ_ONCE(perm_group_timeout);
+
+	if (!timeout)
+		return;
+
+	schedule_delayed_work(&perm_group_work, secs_to_jiffies(timeout));
 }
 
 static void perm_group_watchdog(struct work_struct *work)
-- 
2.51.0


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

* Re: [PATCH] fanotify: stop permission watchdog when timeout is zero
  2026-07-30  7:06 [PATCH] fanotify: stop permission watchdog when timeout is zero Yichong Chen
@ 2026-07-30  9:55 ` Jan Kara
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Kara @ 2026-07-30  9:55 UTC (permalink / raw)
  To: Yichong Chen
  Cc: jack, amir73il, repnop, mszeredi, linux-fsdevel, linux-kernel

On Thu 30-07-26 15:06:48, Yichong Chen wrote:
> The fanotify permission watchdog can be disabled by writing zero to
> fs/fanotify/watchdog_timeout.  fanotify_perm_watchdog_group_add() already
> checks for a zero timeout before scheduling the watchdog.
> 
> However, once the watchdog work has been scheduled, perm_group_watchdog()
> unconditionally schedules itself again with the current timeout.  If the
> sysctl is changed to zero while the work is active, secs_to_jiffies(0)
> causes the work to be rescheduled immediately, resulting in a kworker
> busy loop.
> 
> Read the timeout once in perm_group_watchdog_schedule() and do not
> schedule the work when it is zero.  This lets a running watchdog stop
> after the next execution when the sysctl is set to zero.
> 
> Fixes: b8cf8fda522d ("fanotify: add watchdog for permission events")
> Signed-off-by: Yichong Chen <chenyichong@uniontech.com>

Thanks! I've added the patch to my tree.

								Honza

> ---
>  fs/notify/fanotify/fanotify_user.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> index b604e3da58ad..9ee373ff5840 100644
> --- a/fs/notify/fanotify/fanotify_user.c
> +++ b/fs/notify/fanotify/fanotify_user.c
> @@ -112,7 +112,12 @@ static DECLARE_DELAYED_WORK(perm_group_work, perm_group_watchdog);
>  
>  static void perm_group_watchdog_schedule(void)
>  {
> -	schedule_delayed_work(&perm_group_work, secs_to_jiffies(perm_group_timeout));
> +	int timeout = READ_ONCE(perm_group_timeout);
> +
> +	if (!timeout)
> +		return;
> +
> +	schedule_delayed_work(&perm_group_work, secs_to_jiffies(timeout));
>  }
>  
>  static void perm_group_watchdog(struct work_struct *work)
> -- 
> 2.51.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

end of thread, other threads:[~2026-07-30  9:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-30  7:06 [PATCH] fanotify: stop permission watchdog when timeout is zero Yichong Chen
2026-07-30  9:55 ` Jan Kara

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®