From: "yukuai (C)" <yukuai3@huawei.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: <gregkh@linuxfoundation.org>, <rafael@kernel.org>,
<oleg@redhat.com>, <jack@suse.cz>, <linux-kernel@vger.kernel.org>,
<zhengbin13@huawei.com>, <yi.zhang@huawei.com>,
<chenxiang66@hisilicon.com>, <xiexiuqi@huawei.com>
Subject: Re: [PATCH] debugfs: fix potential infinite loop in debugfs_remove_recursive
Date: Thu, 14 Nov 2019 10:01:23 +0800 [thread overview]
Message-ID: <a399ae58-a467-3ff9-5a01-a4a2cdcf4fd6@huawei.com> (raw)
In-Reply-To: <20191113151755.7125e914@gandalf.local.home>
Thanks for your explanation
On 2019/11/14 4:17, Steven Rostedt wrote:
> On Thu, 31 Oct 2019 21:34:44 +0800
> yu kuai <yukuai3@huawei.com> wrote:
>
>> 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
>
> s/bucause/because/
>
>> 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
>> + */
>
> Nit, multi-line comments should be of the form:
>
> /*
> * comment line 1
> * comment line 2
> */
>
> Not
>
> /* comment line 1
> * comment line 2
> */
>
> It's known that the networking folks like that method, but it's not
> acceptable anywhere outside of networking.
>
Do you agree with that list_empty(&chile->d_subdirs) here is not
appropriate? Since it can't skip the subdirs that is not
simple_positive(simple_positive() will return false), which is the
reason of infinite loop.
>> + if (!simple_empty(child)) {
>
> Have you tried this with lockdep enabled? I'm thinking that you might
> get a splat with holding parent->d_lock and simple_empty(child) taking
> the child->d_lock.
The locks are taken and released in the right order:
take parent->d_lock
take child->d_lock
list_for_each_entry(c, &child->d_sundirs, d_child)
take c->d_lock
release c->d_lock
release child->d_lock
release parent->d_lock
I don't see anything wrong, am I missing something?
Thanks
Yu Kuai
>
> -- Steve
>
>
>> spin_unlock(&parent->d_lock);
>> inode_unlock(d_inode(parent));
>> parent = child;
>
>
> .
>
next prev parent reply other threads:[~2019-11-14 2:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-31 13:34 yu kuai
2019-11-13 20:17 ` Steven Rostedt
2019-11-14 2:01 ` yukuai (C) [this message]
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)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a399ae58-a467-3ff9-5a01-a4a2cdcf4fd6@huawei.com \
--to=yukuai3@huawei.com \
--cc=chenxiang66@hisilicon.com \
--cc=gregkh@linuxfoundation.org \
--cc=jack@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=rafael@kernel.org \
--cc=rostedt@goodmis.org \
--cc=xiexiuqi@huawei.com \
--cc=yi.zhang@huawei.com \
--cc=zhengbin13@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®