Linux driver-core infrastructure
 help / color / mirror / Atom feed
* [PATCH] sysfs: don't remove existing directory on update failure
@ 2026-05-20 13:05 Greg Kroah-Hartman
  2026-05-20 13:34 ` Rafael J. Wysocki
  2026-05-20 14:45 ` Danilo Krummrich
  0 siblings, 2 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2026-05-20 13:05 UTC (permalink / raw)
  To: driver-core
  Cc: linux-kernel, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Rajat Jain, stable

When sysfs_update_group() is called for a named group and create_files()
fails (e.g. -ENOMEM), internal_create_group() calls kernfs_remove(kn) on
the group directory.  In the update path, kn was obtained via
kernfs_find_and_get() and refers to a directory that already existed
before this call.  Removing it silently destroys a sysfs group that the
caller did not create.

Only remove the directory if we created it ourselves.  On update failure
the directory remains as it is left empty by remove_files() inside
create_files(), but can be repopulated by a retry.

Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Rajat Jain <rajatja@google.com>
Fixes: c855cf2759d2 ("sysfs: Fix internal_create_group() for named group updates")
Cc: stable <stable@kernel.org>
Assisted-by: gkh_clanker_t1000
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 fs/sysfs/group.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index 182e54e575ee..4e1e4f18a166 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -188,7 +188,7 @@ static int internal_create_group(struct kobject *kobj, int update,
 	kernfs_get(kn);
 	error = create_files(kn, kobj, uid, gid, grp, update);
 	if (error) {
-		if (grp->name)
+		if (grp->name && !update)
 			kernfs_remove(kn);
 	}
 	kernfs_put(kn);
-- 
2.54.0


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

* [PATCH] sysfs: don't remove existing directory on update failure
@ 2026-05-20 13:06 Greg Kroah-Hartman
  2026-05-20 13:12 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2026-05-20 13:06 UTC (permalink / raw)
  To: driver-core
  Cc: linux-kernel, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Rajat Jain, stable

When sysfs_update_group() is called for a named group and create_files()
fails (e.g. -ENOMEM), internal_create_group() calls kernfs_remove(kn) on
the group directory.  In the update path, kn was obtained via
kernfs_find_and_get() and refers to a directory that already existed
before this call.  Removing it silently destroys a sysfs group that the
caller did not create.

Only remove the directory if we created it ourselves.  On update failure
the directory remains as it is left empty by remove_files() inside
create_files(), but can be repopulated by a retry.

Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Rajat Jain <rajatja@google.com>
Fixes: c855cf2759d2 ("sysfs: Fix internal_create_group() for named group updates")
Cc: stable <stable@kernel.org>
Assisted-by: gkh_clanker_t1000
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 fs/sysfs/group.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index 182e54e575ee..4e1e4f18a166 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -188,7 +188,7 @@ static int internal_create_group(struct kobject *kobj, int update,
 	kernfs_get(kn);
 	error = create_files(kn, kobj, uid, gid, grp, update);
 	if (error) {
-		if (grp->name)
+		if (grp->name && !update)
 			kernfs_remove(kn);
 	}
 	kernfs_put(kn);
-- 
2.54.0


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

* Re: [PATCH] sysfs: don't remove existing directory on update failure
  2026-05-20 13:06 [PATCH] sysfs: don't remove existing directory on update failure Greg Kroah-Hartman
@ 2026-05-20 13:12 ` Greg Kroah-Hartman
  0 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2026-05-20 13:12 UTC (permalink / raw)
  To: driver-core
  Cc: linux-kernel, Rafael J. Wysocki, Danilo Krummrich, Rajat Jain,
	stable

On Wed, May 20, 2026 at 03:06:03PM +0200, Greg Kroah-Hartman wrote:
> When sysfs_update_group() is called for a named group and create_files()
> fails (e.g. -ENOMEM), internal_create_group() calls kernfs_remove(kn) on
> the group directory.  In the update path, kn was obtained via
> kernfs_find_and_get() and refers to a directory that already existed
> before this call.  Removing it silently destroys a sysfs group that the
> caller did not create.
> 
> Only remove the directory if we created it ourselves.  On update failure
> the directory remains as it is left empty by remove_files() inside
> create_files(), but can be repopulated by a retry.
> 
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Danilo Krummrich <dakr@kernel.org>
> Cc: Rajat Jain <rajatja@google.com>
> Fixes: c855cf2759d2 ("sysfs: Fix internal_create_group() for named group updates")
> Cc: stable <stable@kernel.org>
> Assisted-by: gkh_clanker_t1000
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>  fs/sysfs/group.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
> index 182e54e575ee..4e1e4f18a166 100644
> --- a/fs/sysfs/group.c
> +++ b/fs/sysfs/group.c
> @@ -188,7 +188,7 @@ static int internal_create_group(struct kobject *kobj, int update,
>  	kernfs_get(kn);
>  	error = create_files(kn, kobj, uid, gid, grp, update);
>  	if (error) {
> -		if (grp->name)
> +		if (grp->name && !update)
>  			kernfs_remove(kn);
>  	}
>  	kernfs_put(kn);
> -- 
> 2.54.0
> 

Ugh, sent this twice, sorry for the noise, only one matters :)

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

* Re: [PATCH] sysfs: don't remove existing directory on update failure
  2026-05-20 13:05 Greg Kroah-Hartman
@ 2026-05-20 13:34 ` Rafael J. Wysocki
  2026-05-20 14:45 ` Danilo Krummrich
  1 sibling, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2026-05-20 13:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: driver-core, linux-kernel, Rafael J. Wysocki, Danilo Krummrich,
	Rajat Jain, stable

On Wed, May 20, 2026 at 3:05 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> When sysfs_update_group() is called for a named group and create_files()
> fails (e.g. -ENOMEM), internal_create_group() calls kernfs_remove(kn) on
> the group directory.  In the update path, kn was obtained via
> kernfs_find_and_get() and refers to a directory that already existed
> before this call.  Removing it silently destroys a sysfs group that the
> caller did not create.
>
> Only remove the directory if we created it ourselves.  On update failure
> the directory remains as it is left empty by remove_files() inside
> create_files(), but can be repopulated by a retry.
>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Danilo Krummrich <dakr@kernel.org>
> Cc: Rajat Jain <rajatja@google.com>
> Fixes: c855cf2759d2 ("sysfs: Fix internal_create_group() for named group updates")
> Cc: stable <stable@kernel.org>
> Assisted-by: gkh_clanker_t1000
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

No issues found, so

Reviewed-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>

> ---
>  fs/sysfs/group.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
> index 182e54e575ee..4e1e4f18a166 100644
> --- a/fs/sysfs/group.c
> +++ b/fs/sysfs/group.c
> @@ -188,7 +188,7 @@ static int internal_create_group(struct kobject *kobj, int update,
>         kernfs_get(kn);
>         error = create_files(kn, kobj, uid, gid, grp, update);
>         if (error) {
> -               if (grp->name)
> +               if (grp->name && !update)
>                         kernfs_remove(kn);
>         }
>         kernfs_put(kn);
> --
> 2.54.0
>

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

* Re: [PATCH] sysfs: don't remove existing directory on update failure
  2026-05-20 13:05 Greg Kroah-Hartman
  2026-05-20 13:34 ` Rafael J. Wysocki
@ 2026-05-20 14:45 ` Danilo Krummrich
  1 sibling, 0 replies; 5+ messages in thread
From: Danilo Krummrich @ 2026-05-20 14:45 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: driver-core, linux-kernel, Rafael J. Wysocki, Rajat Jain, stable

On Wed May 20, 2026 at 3:05 PM CEST, Greg Kroah-Hartman wrote:
> When sysfs_update_group() is called for a named group and create_files()
> fails (e.g. -ENOMEM), internal_create_group() calls kernfs_remove(kn) on
> the group directory.  In the update path, kn was obtained via
> kernfs_find_and_get() and refers to a directory that already existed
> before this call.  Removing it silently destroys a sysfs group that the
> caller did not create.
>
> Only remove the directory if we created it ourselves.  On update failure
> the directory remains as it is left empty by remove_files() inside
> create_files(), but can be repopulated by a retry.
>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Danilo Krummrich <dakr@kernel.org>
> Cc: Rajat Jain <rajatja@google.com>
> Fixes: c855cf2759d2 ("sysfs: Fix internal_create_group() for named group updates")
> Cc: stable <stable@kernel.org>
> Assisted-by: gkh_clanker_t1000
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Reviewed-by: Danilo Krummrich <dakr@kernel.org>

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

end of thread, other threads:[~2026-05-20 14:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-20 13:06 [PATCH] sysfs: don't remove existing directory on update failure Greg Kroah-Hartman
2026-05-20 13:12 ` Greg Kroah-Hartman
  -- strict thread matches above, loose matches on Subject: below --
2026-05-20 13:05 Greg Kroah-Hartman
2026-05-20 13:34 ` Rafael J. Wysocki
2026-05-20 14:45 ` Danilo Krummrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox