LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] fs: sysfs: do not remove files if group is null
@ 2021-08-19 19:10 Daniel Steger
  2021-08-21 11:52 ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Steger @ 2021-08-19 19:10 UTC (permalink / raw)
  To: gregkh, rafael; +Cc: linux-kernel, Daniel Steger

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


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

* Re: [PATCH] fs: sysfs: do not remove files if group is null
  2021-08-19 19:10 [PATCH] fs: sysfs: do not remove files if group is null Daniel Steger
@ 2021-08-21 11:52 ` Greg KH
  0 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2021-08-21 11:52 UTC (permalink / raw)
  To: Daniel Steger; +Cc: rafael, linux-kernel

On Thu, Aug 19, 2021 at 12:10:20PM -0700, Daniel Steger wrote:
> 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.

What driver is doing this today?

> On driver exist ensure to unregister your child device.

What child device?  Why is a platform driver creating a child device at
all?

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

What about groups without names?  Will then now not be removed properly?
Why does the name matter here?

thanks,

greg k-h

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

* Re: [PATCH] fs: sysfs: do not remove files if group is null
  2021-08-18  1:07 Daniel Steger
@ 2021-08-18  5:35 ` Greg KH
  0 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2021-08-18  5:35 UTC (permalink / raw)
  To: Daniel Steger; +Cc: rafael, linux-kernel

On Tue, Aug 17, 2021 at 06:07:57PM -0700, Daniel Steger wrote:
> This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.

Now deleted.

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

* [PATCH] fs: sysfs: do not remove files if group is null
@ 2021-08-18  1:07 Daniel Steger
  2021-08-18  5:35 ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Steger @ 2021-08-18  1:07 UTC (permalink / raw)
  To: gregkh, rafael; +Cc: linux-kernel, Daniel Steger

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

This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.

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

* Re: [PATCH] fs: sysfs: do not remove files if group is null
  2021-08-17 16:18   ` gregkh
@ 2021-08-17 16:19     ` gregkh
  0 siblings, 0 replies; 7+ messages in thread
From: gregkh @ 2021-08-17 16:19 UTC (permalink / raw)
  To: Daniel Steger; +Cc: rafael, linux-kernel

On Tue, Aug 17, 2021 at 06:18:07PM +0200, gregkh@linuxfoundation.org wrote:
> > -----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
> 
> What is the message id of this, I do not see it on my side at all.

lore.kernel.org also never got this, so I think the issue might be on
your side :(


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

* Re: [PATCH] fs: sysfs: do not remove files if group is null
  2021-08-17 16:13 ` Daniel Steger
@ 2021-08-17 16:18   ` gregkh
  2021-08-17 16:19     ` gregkh
  0 siblings, 1 reply; 7+ messages in thread
From: gregkh @ 2021-08-17 16:18 UTC (permalink / raw)
  To: Daniel Steger; +Cc: rafael, linux-kernel

A: http://en.wikipedia.org/wiki/Top_post
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

A: No.
Q: Should I include quotations after my reply?

http://daringfireball.net/2007/07/on_top

On Tue, Aug 17, 2021 at 04:13:48PM +0000, Daniel Steger wrote:
> Hi Greg, Rafael, 
> 
> Have you had a chance to review this patch?

What 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

What is the message id of this, I do not see it on my side at all.

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

At the least, wrap your lines at 72 columns, we can't take this as-is...

thanks,

greg k-h

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

* RE: [PATCH] fs: sysfs: do not remove files if group is null
       [not found] <20210809204228.2987376-1-daniel.steger@xilinx.com>
@ 2021-08-17 16:13 ` Daniel Steger
  2021-08-17 16:18   ` gregkh
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Steger @ 2021-08-17 16:13 UTC (permalink / raw)
  To: Daniel Steger, gregkh, rafael; +Cc: linux-kernel

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


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

end of thread, other threads:[~2021-08-21 11:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-19 19:10 [PATCH] fs: sysfs: do not remove files if group is null Daniel Steger
2021-08-21 11:52 ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2021-08-18  1:07 Daniel Steger
2021-08-18  5:35 ` Greg KH
     [not found] <20210809204228.2987376-1-daniel.steger@xilinx.com>
2021-08-17 16:13 ` Daniel Steger
2021-08-17 16:18   ` gregkh
2021-08-17 16:19     ` gregkh

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