Skip to content

Commit 159f5bd

Browse files
jmberg-intelgregkh
authored andcommitted
debugfs: initialize cancellations earlier
Tetsuo Handa pointed out that in the (now reverted) lockdep commit I initialized the data too late. The same is true for the cancellation data, it must be initialized before the cmpxchg(), otherwise it may be done twice and possibly even overwriting data in there already when there's a race. Fix that, which also requires destroying the mutex in case we lost the race. Fixes: 8c88a47 ("debugfs: add API to allow debugfs operations cancellation") Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: Johannes Berg <johannes.berg@intel.com> Link: https://lore.kernel.org/r/20231221150444.1e47a0377f80.If7e8ba721ba2956f12c6e8405e7d61e154aa7ae7@changeid Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d400543 commit 159f5bd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

fs/debugfs/file.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ int debugfs_file_get(struct dentry *dentry)
104104
~DEBUGFS_FSDATA_IS_REAL_FOPS_BIT);
105105
refcount_set(&fsd->active_users, 1);
106106
init_completion(&fsd->active_users_drained);
107+
INIT_LIST_HEAD(&fsd->cancellations);
108+
mutex_init(&fsd->cancellations_mtx);
109+
107110
if (cmpxchg(&dentry->d_fsdata, d_fsd, fsd) != d_fsd) {
111+
mutex_destroy(&fsd->cancellations_mtx);
108112
kfree(fsd);
109113
fsd = READ_ONCE(dentry->d_fsdata);
110114
}
111-
INIT_LIST_HEAD(&fsd->cancellations);
112-
mutex_init(&fsd->cancellations_mtx);
113115
}
114116

115117
/*

0 commit comments

Comments
 (0)