[PATCH v2 2/2] fuse: do not schedule dentry_tree_work after fuse_dentry_tree_cleanup()

From: Sang-Heon Jeon

Date: Fri Nov 20 2026 - 10:02:43 EST


fuse_dentry_tree_cleanup() cancels dentry_tree_work at module unload.

But a sysfs write can call inval_wq_set() after that and schedule the
work again, leading to use-after-free.

So do not schedule the work in inval_wq_set() after
fuse_dentry_tree_cleanup() cancels it. Also hold kernel_param_lock()
in fuse_dentry_tree_cleanup(), because a sysfs write can call
inval_wq_set() at the same time.

Fixes: ab84ad597386 ("fuse: new work queue to periodically invalidate expired dentries")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Sang-Heon Jeon <ekffu200098@xxxxxxxxx>
---
fs/fuse/dir.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 0d5d04df477b..04ca6c9be2bf 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -63,7 +63,10 @@ static int inval_wq_set(const char *val, const struct kernel_param *kp)

*((unsigned int *)kp->arg) = num;

- /* Defer the work until fuse_dentry_tree_init() sets it up. */
+ /*
+ * Do not touch the work before fuse_dentry_tree_init() or after
+ * fuse_dentry_tree_cleanup().
+ */
if (!inval_wq_ready)
return 0;

@@ -243,8 +246,11 @@ void fuse_dentry_tree_cleanup(void)
{
int i;

+ kernel_param_lock(THIS_MODULE);
+ inval_wq_ready = false;
inval_wq = 0;
cancel_delayed_work_sync(&dentry_tree_work);
+ kernel_param_unlock(THIS_MODULE);

for (i = 0; i < FUSE_HASH_SIZE; i++)
WARN_ON_ONCE(!RB_EMPTY_ROOT(&dentry_hash[i].tree));
--
2.53.0