[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 09/11] ubifs: sysfs: Use kset_create_and_add() for ubifs_kset
- To: Ian Rogers <irogers@xxxxxxxxxx>, Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>, "Rafael J . Wysocki" <rafael@xxxxxxxxxx>, Danilo Krummrich <dakr@xxxxxxxxxx>, Miguel Ojeda <ojeda@xxxxxxxxxx>, Kees Cook <kees@xxxxxxxxxx>, Nathan Chancellor <nathan@xxxxxxxxxx>
- From: Zhihao Cheng <chengzhihao1@xxxxxxxxxx>
- Date: Wed, 14 Oct 2026 19:51:20 +0800
- Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=dkim header.d=huawei.com header.i="@huawei.com" header.h=From
- Cc: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>, Bill Wendling <morbo@xxxxxxxxxx>, Justin Stitt <justinstitt@xxxxxxxxxx>, Jonathan Corbet <corbet@xxxxxxx>, Madhavan Srinivasan <maddy@xxxxxxxxxxxxx>, Michael Ellerman <mpe@xxxxxxxxxxxxxx>, Nicholas Piggin <npiggin@xxxxxxxxx>, Christophe Leroy <chleroy@xxxxxxxxxx>, Nayna Jain <nayna@xxxxxxxxxxxxx>, Yoshinori Sato <ysato@xxxxxxxxxxxxxxxxxxxx>, Rich Felker <dalias@xxxxxxxx>, John Paul Adrian Glaubitz <glaubitz@xxxxxxxxxxxxxxxxxxx>, Viresh Kumar <viresh.kumar@xxxxxxxxxx>, David Teigland <teigland@xxxxxxxxxx>, Alexander Aring <aahringo@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>, Heiko Carstens <hca@xxxxxxxxxxxxx>, Vasily Gorbik <gor@xxxxxxxxxxxxx>, Alexander Gordeev <agordeev@xxxxxxxxxxxxx>, Christian Borntraeger <borntraeger@xxxxxxxxxxxxx>, Sven Schnelle <svens@xxxxxxxxxxxxx>, Richard Weinberger <richard@xxxxxx>, Felix Kuehling <Felix.Kuehling@xxxxxxx>, Alex Deucher <alexander.deucher@xxxxxxx>, Christian König <christian.koenig@xxxxxxx>, <driver-core@xxxxxxxxxxxxxxx>, <llvm@xxxxxxxxxxxxxxx>, <linux-hardening@xxxxxxxxxxxxxxx>, <linux-doc@xxxxxxxxxxxxxxx>, <linuxppc-dev@xxxxxxxxxxxxxxxx>, <linux-sh@xxxxxxxxxxxxxxx>, <linux-pm@xxxxxxxxxxxxxxx>, <linux-acpi@xxxxxxxxxxxxxxx>, <gfs2@xxxxxxxxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>, <linux-s390@xxxxxxxxxxxxxxx>, <linux-mtd@xxxxxxxxxxxxxxxxxxx>, <amd-gfx@xxxxxxxxxxxxxxxxxxxxx>, <dri-devel@xxxxxxxxxxxxxxxxxxxxx>, <linux-kernel@xxxxxxxxxxxxxxx>
- Delivery-date: Thu, 15 Oct 2026 12:05:31 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
在 2026/10/14 6:39, Ian Rogers 写道:
ubifs_kset was a static struct kset using a custom ubifs_ktype that
had no default_groups and no .release callback. With
CONFIG_DEBUG_KOBJECT_RELEASE=y, unloading the ubifs module while delayed
kobject release is pending causes a use-after-free on the static kset.
Replace the static ubifs_kset and empty ubifs_ktype with a dynamically
allocated kset via kset_create_and_add().
Fixes: 203a55f04f66 ("ubifs: Fix memory leak in ubifs_sysfs_init()")
Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
fs/ubifs/sysfs.c | 24 +++++++-----------------
1 file changed, 7 insertions(+), 17 deletions(-)
Tested-by: Zhihao Cheng <chengzhihao1@xxxxxxxxxx>
Reviewed-by: Zhihao Cheng <chengzhihao1@xxxxxxxxxx>
diff --git a/fs/ubifs/sysfs.c b/fs/ubifs/sysfs.c
index dbf967dcf26e..e20931e3a62f 100644
--- a/fs/ubifs/sysfs.c
+++ b/fs/ubifs/sysfs.c
@@ -80,13 +80,7 @@ static const struct kobj_type ubifs_sb_ktype = {
.release = ubifs_sb_release,
};
-static const struct kobj_type ubifs_ktype = {
- .sysfs_ops = &ubifs_attr_ops,
-};
-
-static struct kset ubifs_kset = {
- .kobj = {.ktype = &ubifs_ktype},
-};
+static struct kset *ubifs_kset;
int ubifs_sysfs_register(struct ubifs_info *c)
{
@@ -107,7 +101,7 @@ int ubifs_sysfs_register(struct ubifs_info *c)
goto out_free;
}
- c->kobj.kset = &ubifs_kset;
+ c->kobj.kset = ubifs_kset;
init_completion(&c->kobj_unregister);
ret = kobject_init_and_add(&c->kobj, &ubifs_sb_ktype, NULL,
@@ -139,18 +133,14 @@ void ubifs_sysfs_unregister(struct ubifs_info *c)
int __init ubifs_sysfs_init(void)
{
- int ret;
+ ubifs_kset = kset_create_and_add("ubifs", NULL, fs_kobj);
+ if (!ubifs_kset)
+ return -ENOMEM;
- kobject_set_name(&ubifs_kset.kobj, "ubifs");
- ubifs_kset.kobj.parent = fs_kobj;
- ret = kset_register(&ubifs_kset);
- if (ret)
- kset_put(&ubifs_kset);
-
- return ret;
+ return 0;
}
void ubifs_sysfs_exit(void)
{
- kset_unregister(&ubifs_kset);
+ kset_unregister(ubifs_kset);
}
|