linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] debugfs: fix potential infinite loop in debugfs_remove_recursive
@ 2019-10-31 13:34 yu kuai
  2019-11-13 20:17 ` Steven Rostedt
  0 siblings, 1 reply; 11+ messages in thread
From: yu kuai @ 2019-10-31 13:34 UTC (permalink / raw)
  To: gregkh, rafael, oleg, rostedt, jack
  Cc: linux-kernel, zhengbin13, yi.zhang, chenxiang66, xiexiuqi

debugfs_remove_recursive uses list_empty to judge weather a dentry has
any subdentry or not. This can lead to infinite loop when any subdir is in
use.

The problem was discoverd by the following steps in the console.
1. use debugfs_create_dir to create a dir and multiple subdirs(insmod);
2. cd to the subdir with depth not less than 2;
3. call debugfs_remove_recursive(rmmod).

After removing the subdir, the infinite loop is triggered bucause
debugfs_remove_recursive uses list_empty to judge if the current dir
doesn't have any subdentry, if so, remove the current dir and which
will never happen.

Fix the problem by using simple_empty instead of list_empty.

Fixes: 776164c1faac ('debugfs: debugfs_remove_recursive() must not rely on list_empty(d_subdirs)')
Reported-by: chenxiang66@hisilicon.com
Signed-off-by: yu kuai <yukuai3@huawei.com>
---
 fs/debugfs/inode.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 7b975db..42b28acc 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -773,8 +773,10 @@ void debugfs_remove_recursive(struct dentry *dentry)
 		if (!simple_positive(child))
 			continue;
 
-		/* perhaps simple_empty(child) makes more sense */
-		if (!list_empty(&child->d_subdirs)) {
+		/* use simple_empty to prevent infinite loop when any
+		 * subdentry of child is in use
+		 */
+		if (!simple_empty(child)) {
 			spin_unlock(&parent->d_lock);
 			inode_unlock(d_inode(parent));
 			parent = child;
-- 
2.7.4


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

end of thread, other threads:[~2019-11-15  2:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-31 13:34 [PATCH] debugfs: fix potential infinite loop in debugfs_remove_recursive yu kuai
2019-11-13 20:17 ` Steven Rostedt
2019-11-14  2:01   ` yukuai (C)
2019-11-14  2:43     ` Steven Rostedt
2019-11-14  3:20       ` yukuai (C)
2019-11-14  6:59       ` yukuai (C)
2019-11-14 14:34         ` Steven Rostedt
2019-11-15  1:47           ` yukuai (C)
2019-11-15  1:53             ` Steven Rostedt
2019-11-15  2:13               ` yukuai (C)
2019-11-15  1:57             ` yukuai (C)

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).