From: Daniel Steger <dsteger@xilinx.com>
To: Daniel Steger <dsteger@xilinx.com>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"rafael@kernel.org" <rafael@kernel.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] fs: sysfs: do not remove files if group is null
Date: Tue, 17 Aug 2021 16:13:48 +0000 [thread overview]
Message-ID: <BY5PR02MB68170E18D6B5C79BB0AC9083C1FE9@BY5PR02MB6817.namprd02.prod.outlook.com> (raw)
In-Reply-To: <20210809204228.2987376-1-daniel.steger@xilinx.com>
Hi Greg, Rafael,
Have you had a chance to review this patch?
Thank You,
Daniel
-----Original Message-----
From: Daniel Steger <daniel.steger@xilinx.com>
Sent: Monday, August 9, 2021 1:42 PM
To: gregkh@linuxfoundation.org; rafael@kernel.org
Cc: linux-kernel@vger.kernel.org; Daniel Steger <dsteger@xilinx.com>
Subject: [PATCH] fs: sysfs: do not remove files if group is null
The current implementation allows the remove_files() API to be called without checking if the grp->name is null. Ensure that the group name is valid prior to removing files.
This patch fixes a race condition where device_del() will cleanup sysfs entries prior to device managed sysfs entries. This results in a NULL group->name and a system error during device cleanup.
To reproduce the issue, simply create a new child device in a platform driver of your choice. Add a sysfs file group using devm API. On driver exist ensure to unregister your child device.
Do not call devm_device_remove_group() and leave it up to the implementation to automatically clean up the files. Here is where you will see a kernel error complaining that the files have already been removed.
Signed-off-by: Daniel Steger <daniel.steger@xilinx.com>
---
fs/sysfs/group.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 64e6a6698935..023b40840f36 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -286,9 +286,10 @@ void sysfs_remove_group(struct kobject *kobj,
kernfs_get(kn);
}
- remove_files(kn, grp);
- if (grp->name)
+ if (grp->name) {
+ remove_files(kn, grp);
kernfs_remove(kn);
+ }
kernfs_put(kn);
}
--
2.25.1
next parent reply other threads:[~2021-08-17 16:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20210809204228.2987376-1-daniel.steger@xilinx.com>
2021-08-17 16:13 ` Daniel Steger [this message]
2021-08-17 16:18 ` [PATCH] fs: sysfs: do not remove files if group is null gregkh
2021-08-17 16:19 ` gregkh
2021-08-18 1:07 Daniel Steger
2021-08-18 5:35 ` Greg KH
2021-08-19 19:10 Daniel Steger
2021-08-21 11:52 ` Greg KH
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=BY5PR02MB68170E18D6B5C79BB0AC9083C1FE9@BY5PR02MB6817.namprd02.prod.outlook.com \
--to=dsteger@xilinx.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).