Add __must_init and require explicit kobj_type::release
Subsystems (31)
v3 cover Add __must_init and require explicit kobj_type::release
Clang supports the 'require_explicit_initialization' attribute on struct fields to enforce that the field is explicitly initialized when an aggregate object is constructed, emitting -Wuninitialized-explicit-init (enabled by default) if the field is omitted.
Following discussion at the Linux Plumbers Conference [1], patch 1 adds the attribute to include/linux/compiler_attributes.h as __must_init. In v1 it was called __require_explicit_initialization. Kees picked up that patch with a first seq_file user [2], and in that thread Greg suggested the shorter __must_init spelling, which Kees and Miguel agreed to. As the attribute did not land in the v7.4 merge window, Kees asked that this series carry the renamed attribute.
As Documentation/core-api/kobject.rst notes:
"One important point cannot be overstated: every kobject must have a release() method, and the kobject must persist (in a consistent state) until that method is called. If these constraints are not met, the code is flawed."
Annotating struct kobj_type::release caught struct kobj_type definitions across the tree that omitted .release:
- Patches 2-8 fix struct kobj_type definitions where dynamically allocated kobjects, ksets, or enclosing structures were either leaked on kobject_put(), freed prematurely before kobject release, or missing proper static initializers.
- Patch 9 annotates struct kobj_type::release with __must_init and explicitly sets .release = NULL (with explanatory comments prefixed with "Pre-existing:") on the remaining legacy struct kobj_type definitions whose kobjects are static, per-CPU, permanent firmware structures, or embedded in devm- or parent-managed allocations.
Danilo Krummrich offered to route the series as a whole through the driver-core tree [3]. Subsystem maintainer Acked-by tags are still needed (and would be much appreciated!) for the following three patches:
- Patch 2: powerpc/secvar: Add missing kobject release callback to secvar_ktype
- Patch 3: sh: sq: Add missing kobject release callback to ktype_percpu_entry
- Patch 6: xen/sys-hypervisor: Add release callback to hyp_sysfs_kobj_type
Note on tool use: An LLM coding assistant was used to help audit the compiler diagnostics across the tree, draft the fixes and changelog descriptions, and verify builds and review feedback.
Changes in v3:
- Rebased on v7.4-rc1.
- Note in cover letter that patches 2 (powerpc/secvar), 3 (sh: sq), and 6 (xen/sys-hypervisor) are still awaiting subsystem Acked-by tags for merging through the driver-core tree, and CC those maintainers on the cover letter.
- Patch 1: Add Reviewed-by from Kees Cook; clarify that LLVM issue #232483 affects Clang versions prior to its upstream fix (pointed out by Nathan Chancellor).
- Patch 4 (cpufreq): Drop obsolete reference to cpufreq_governor_dbs in the commit message per Zhongqiu Han; add Reviewed-by from Zhongqiu Han and Acked-by from Rafael J. Wysocki and Viresh Kumar.
- Patch 5 (dlm): Add Acked-by from Alexander Aring.
- Patch 8 (drm/amdkfd): Add Reviewed-by from Felix Kuehling.
- Patch 9 (kobject): Fix omapfb manager-sysfs.c and overlay-sysfs.c comments to describe managers[] and overlays[] as dynamically allocated rather than static and note the CONFIG_DEBUG_KOBJECT_RELEASE hazard, fix a struct-vs-member wording nit in usnic_ib_sysfs.c, and generalize the commit message note on CONFIG_DEBUG_KOBJECT_RELEASE (reported by Sashiko).
Changes in v2:
- Rebased on v7.3-16928-g83f32c773255 (v7.4 merge window).
- Patch 1: Rename __require_explicit_initialization to __must_init per Greg Kroah-Hartman; document the Clang >= 20 requirement per Miguel Ojeda; note the Clang gap for file-scope objects without an initializer reported by Kees Cook; add tags from v1 and from Kees's posting.
- Move LLM assistance attribution from Assisted-by tags to this cover letter per commit 1e035297ffda ("docs: remove Assisted-by references").
- Patch 4 (cpufreq): Use "cpufreq: governor:" prefix, drop Fixes tag, fix typo, and remove the redundant runtime assignment in cpufreq_dbs_governor_init() per Zhongqiu Han.
- Dropped v1 patch 5 (ACPI: CPPC), already fixed upstream by commit 27954e29d7de ("ACPI: CPPC: Release CPC descriptors through kobject").
- Patch 5 (dlm): Call kobject_del() before dlm_recoverd_stop() in release_lockspace() and the new_lockspace() error path, and wait on a new ls_kobj_done completion before freeing the lockspace or dropping the module reference, avoiding races with delayed kobject release.
- Dropped v1 patch 8 (s390/sclp_mem) per Sumanth Korikkar: the /sys/firmware/memory/memoryX kobjects are permanent, so sclp_mem.c is folded into patch 9 with .release = NULL.
- Patch 7 (ubifs): Add Tested-by and Reviewed-by from Zhihao Cheng.
- Patch 8 (drm/amdkfd): Check q->kobj.state_in_sysfs before kobject_del() in kfd_procfs_del_queue().
- Patch 9 (kobject): Cover sclp_mem.c and the new amdgpu_ualink.c ualink_xcp_info_ktype, fix the overlay-sysfs.c comment, and prefix legacy .release = NULL comments with "Pre-existing:".
- Patch 9 (kobject): The ioat, kunpeng_hccs and omapfb display comments now say that the existing teardown can use-after-free under CONFIG_DEBUG_KOBJECT_RELEASE (reported by Sashiko). Fixing those drivers is left to follow-up patches.
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
[1] https://lpc.events/event/20/contributions/2392/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
Ian Rogers (9):
Compiler Attributes: Add __must_init macro
powerpc/secvar: Add missing kobject release callback to secvar_ktype
sh: sq: Add missing kobject release callback to ktype_percpu_entry
cpufreq: governor: Initialize kobj_type release callback statically
dlm: Free dlm_ls in kobject release callback xen/sys-hypervisor: Add release callback to hyp_sysfs_kobj_type
ubifs: sysfs: Use kset_create_and_add() for ubifs_kset drm/amdkfd: Free queue in procfs_queue_type kobject release callback
kobject: Require explicit initialization of struct kobj_type::release
Documentation/conf.py | 1 + arch/arm64/kernel/cpuinfo.c | 5 ++++ arch/powerpc/kernel/secvar-sysfs.c | 6 +++++ arch/sh/kernel/cpu/sh4/sq.c | 6 +++++ drivers/acpi/sysfs.c | 2 ++ drivers/cpufreq/cpufreq_conservative.c | 5 +++- drivers/cpufreq/cpufreq_governor.c | 4 +-- drivers/cpufreq/cpufreq_governor.h | 1 + drivers/cpufreq/cpufreq_ondemand.c | 5 +++- drivers/dma/ioat/sysfs.c | 7 +++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 5 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 10 +++++++ drivers/gpu/drm/amd/amdkfd/kfd_process.c | 12 ++++++--- drivers/gpu/drm/amd/amdkfd/kfd_queue.c | 5 +++- drivers/infiniband/hw/hfi1/sysfs.c | 5 ++++ drivers/infiniband/hw/usnic/usnic_ib_sysfs.c | 5 ++++ drivers/parisc/pdc_stable.c | 5 ++++ drivers/power/supply/ab8500_fg.c | 5 ++++ drivers/s390/char/sclp_mem.c | 2 ++ drivers/soc/hisilicon/kunpeng_hccs.c | 21 +++++++++++++++ .../fbdev/omap2/omapfb/dss/display-sysfs.c | 7 +++++ .../fbdev/omap2/omapfb/dss/manager-sysfs.c | 8 ++++++ .../fbdev/omap2/omapfb/dss/overlay-sysfs.c | 8 ++++++ drivers/xen/sys-hypervisor.c | 6 +++++ fs/dlm/dlm_internal.h | 1 + fs/dlm/lockspace.c | 26 ++++++++++++++----- fs/erofs/sysfs.c | 10 +++++++ fs/f2fs/sysfs.c | 15 +++++++++++ fs/ocfs2/cluster/masklog.c | 5 ++++ fs/ubifs/sysfs.c | 24 +++++------------ include/linux/compiler_attributes.h | 12 +++++++++ include/linux/kobject.h | 2 +- scripts/checkpatch.pl | 1 + tools/lib/python/kdoc/xforms_lists.py | 1 + 34 files changed, 211 insertions(+), 32 deletions(-)
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.56.0.455.g6c5a503b38-goog
PATCH v3 1/9 Compiler Attributes: Add __must_init macro
Clang supports the 'require_explicit_initialization' attribute on struct fields to indicate that a field must be initialized explicitly by the user when the object is constructed. When an aggregate initializer or uninitialized variable omits an annotated field, Clang emits a -Wuninitialized-explicit-init warning (enabled by default).
Add the __must_init macro to include/linux/compiler_attributes.h (which is included by include/linux/compiler_types.h and include/linux/compiler.h) so kernel structs with error-prone initialization (such as mandatory callbacks or cleanup handlers) can enforce explicit initialization at compile time, as discussed at the Linux Plumbers Conference. The shorter __must_init spelling, rather than the attribute's full name, keeps annotated struct members readable and was suggested by Greg Kroah-Hartman.
Note that Clang versions prior to the fix for
https://github.com/llvm/llvm-project/issues/232483 do not diagnose file-scope objects declared without any initializer (initializers at file scope that omit the field are diagnosed).
Also teach Sphinx (Documentation/conf.py), kernel-doc (tools/lib/python/kdoc/xforms_lists.py), and checkpatch.pl about the new attribute macro.
--- Documentation/conf.py | 1 + include/linux/compiler_attributes.h | 12 ++++++++++++ scripts/checkpatch.pl | 1 + tools/lib/python/kdoc/xforms_lists.py | 1 + 4 files changed, 15 insertions(+)
Documentation/conf.py +1 -0
@@ -203,6 +203,7 @@ c_id_attributes = [ "__noreturn", "__packed", "__pure", + "__must_init", "__section", "__always_unused", "__maybe_unused",
include/linux/compiler_attributes.h +12 -0
@@ -322,6 +322,18 @@*/ #define __pure __attribute__((__pure__)) +/* +* Optional: not supported by gcc +* Optional: only supported since clang >= 20.0 +* +* clang: https://clang.llvm.org/docs/AttributeReference.html#require-explicit-initialization +*/ +#if __has_attribute (__require_explicit_initialization__) +# define __must_init __attribute__((__require_explicit_initialization__)) +#else +# define __must_init +#endif +/* * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-section-function-attribute * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-section-variable-attribute
scripts/checkpatch.pl +1 -0
@@ -6888,6 +6888,7 @@ sub process { "noreturn" => "__noreturn", "packed" => "__packed", "pure" => "__pure", + "require_explicit_initialization" => "__must_init", "section" => "__section", "used" => "__used", "weak" => "__weak"
tools/lib/python/kdoc/xforms_lists.py +1 -0
@@ -36,6 +36,7 @@ class CTransforms: (CMatch("CRYPTO_MINALIGN_ATTR"), ""), (CMatch("__private"), ""), (CMatch("__rcu"), ""), + (CMatch("__must_init"), ""), (CMatch("____cacheline_aligned_in_smp"), ""), (CMatch("____cacheline_aligned"), ""), (CMatch("__cacheline_group_(?:begin|end)"), ""),
Signature · 1 line
2.56.0.455.g6c5a503b38-goog
PATCH v3 2/9 powerpc/secvar: Add missing kobject release callback to secvar_ktype
In reply to Ian RogersIn add_var(), a struct kobject is dynamically allocated with kzalloc_obj() and initialized with secvar_ktype. If kobject_add() or sysfs_create_file() fails, kobject_put(kobj) is called to clean up. However, secvar_ktype does not define a .release callback, which results in a memory leak of kobj (and a pr_debug warning in kobject_cleanup() when CONFIG_DEBUG_KOBJECT_RELEASE is enabled).
Provide a secvar_release() callback that calls kfree(kobj).
--- arch/powerpc/kernel/secvar-sysfs.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/powerpc/kernel/secvar-sysfs.c +6 -0
@@ -126,7 +126,13 @@ static const struct attribute_group secvar_attr_group = { };__ATTRIBUTE_GROUPS (secvar_attr); +static void secvar_release (struct kobject *kobj) +{ +kfree (kobj); +} +static const struct kobj_type secvar_ktype = { + .release = secvar_release, .sysfs_ops = &kobj_sysfs_ops, .default_groups = secvar_attr_groups, };
Signature · 1 line
2.56.0.455.g6c5a503b38-goog
PATCH v3 3/9 sh: sq: Add missing kobject release callback to ktype_percpu_entry
In reply to Ian RogersIn sq_dev_add(), sq_kobject[cpu] is dynamically allocated with kzalloc_obj() and initialized with ktype_percpu_entry. When sq_dev_remove() calls kobject_put(kobj), the kobject is never freed because ktype_percpu_entry lacks a .release callback.
Provide a sq_kobj_release() callback that calls kfree(kobj).
--- arch/sh/kernel/cpu/sh4/sq.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/sh/kernel/cpu/sh4/sq.c +6 -0
@@ -331,7 +331,13 @@ static const struct sysfs_ops sq_sysfs_ops = { .store = sq_sysfs_store, }; +static void sq_kobj_release (struct kobject *kobj) +{ +kfree (kobj); +} +static struct kobj_type ktype_percpu_entry = { + .release = sq_kobj_release, .sysfs_ops = &sq_sysfs_ops, .default_groups = sq_sysfs_groups, };
Signature · 1 line
2.56.0.455.g6c5a503b38-goog
PATCH v3 4/9 cpufreq: governor: Initialize kobj_type release callback statically
In reply to Ian RogersExport cpufreq_dbs_data_release() and initialize .kobj_type.release statically in the ondemand and conservative governors instead of assigning it at runtime in cpufreq_dbs_governor_init().
This prepares for annotating struct kobj_type::release with __must_init.
--- drivers/cpufreq/cpufreq_conservative.c | 5 ++++- drivers/cpufreq/cpufreq_governor.c | 4 ++-- drivers/cpufreq/cpufreq_governor.h | 1 + drivers/cpufreq/cpufreq_ondemand.c | 5 ++++- 4 files changed, 11 insertions(+), 4 deletions(-)
drivers/cpufreq/cpufreq_conservative.c +4 -1
@@ -318,7 +318,10 @@ static void cs_limits(struct cpufreq_policy *policy)static struct dbs_governor cs_governor = { .gov =CPUFREQ_DBS_GOVERNOR_INITIALIZER ("conservative" ), - .kobj_type = { .default_groups = cs_groups }, + .kobj_type = { + .release = cpufreq_dbs_data_release, + .default_groups = cs_groups, + }, .gov_dbs_update = cs_dbs_update, .alloc = cs_alloc, .free = cs_free,
drivers/cpufreq/cpufreq_governor.c +2 -2
@@ -419,7 +419,7 @@ static void free_policy_dbs_info(struct policy_dbs_info *policy_dbs, gov->free (policy_dbs); } -static void cpufreq_dbs_data_release (struct kobject *kobj) +void cpufreq_dbs_data_release (struct kobject *kobj) {struct dbs_data *dbs_data =to_dbs_data (to_gov_attr_set (kobj));struct dbs_governor *gov = dbs_data->gov;
@@ -427,6 +427,7 @@ static void cpufreq_dbs_data_release(struct kobject *kobj) gov->exit (dbs_data);kfree (dbs_data); } +EXPORT_SYMBOL_GPL (cpufreq_dbs_data_release);int cpufreq_dbs_governor_init (struct cpufreq_policy *policy) {
@@ -488,7 +489,6 @@ int cpufreq_dbs_governor_init(struct cpufreq_policy *policy) policy->governor_data = policy_dbs; gov->kobj_type.sysfs_ops = &governor_sysfs_ops; - gov->kobj_type.release = cpufreq_dbs_data_release; ret =kobject_init_and_add (&dbs_data->attr_set.kobj, &gov->kobj_type,get_governor_parent_kobj (policy),"%s" , gov->gov.name);
drivers/cpufreq/cpufreq_governor.h +1 -0
@@ -150,6 +150,7 @@ static inline struct dbs_governor *dbs_governor_of(struct cpufreq_policy *policy }/* Governor callback routines */ +void cpufreq_dbs_data_release (struct kobject *kobj);int cpufreq_dbs_governor_init (struct cpufreq_policy *policy);void cpufreq_dbs_governor_exit (struct cpufreq_policy *policy);int cpufreq_dbs_governor_start (struct cpufreq_policy *policy);
drivers/cpufreq/cpufreq_ondemand.c +4 -1
@@ -374,7 +374,10 @@ static struct od_ops od_ops = {static struct dbs_governor od_dbs_gov = { .gov =CPUFREQ_DBS_GOVERNOR_INITIALIZER ("ondemand" ), - .kobj_type = { .default_groups = od_groups }, + .kobj_type = { + .release = cpufreq_dbs_data_release, + .default_groups = od_groups, + }, .gov_dbs_update = od_dbs_update, .alloc = od_alloc, .free = od_free,
Signature · 1 line
2.56.0.455.g6c5a503b38-goog
PATCH v3 5/9 dlm: Free dlm_ls in kobject release callback
In reply to Ian Rogersstruct dlm_ls embeds a struct kobject (ls_kobj), but dlm_ktype lacked a .release callback and dlm freed the lockspace structure directly via kfree(ls). With CONFIG_DEBUG_KOBJECT_RELEASE=y, freeing ls before the delayed kobject release runs causes a use-after-free, and unloading the module while the delayed release is pending results in an instruction page fault.
Add a completion ls_kobj_done and dlm_ls_release() to complete it when the last kobject reference is dropped, waiting for it in free_lockspace() before kfree(ls) and in the new_lockspace() error path before module_put(). Also delete the kobject via kobject_del() before stopping dlm_recoverd to close the window where concurrent sysfs writes could wake the stopped recovery task.
--- fs/dlm/dlm_internal.h | 1 + fs/dlm/lockspace.c | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-)
fs/dlm/dlm_internal.h +1 -0
@@ -576,6 +576,7 @@ struct dlm_ls {int ls_create_count;/* create/release refcount */ unsigned long ls_flags;/* LSFL_ */ struct kobject ls_kobj; +struct completion ls_kobj_done;struct xarray ls_lkbxa;rwlock_t ls_lkbxa_lock;
fs/dlm/lockspace.c +20 -6
@@ -179,7 +179,15 @@ static const struct sysfs_ops dlm_attr_ops = { .store = dlm_attr_store, }; +static void dlm_ls_release (struct kobject *kobj) +{ + struct dlm_ls *ls = container_of(kobj, struct dlm_ls, ls_kobj); + +complete (&ls->ls_kobj_done); +} +static struct kobj_type dlm_ktype = { + .release = dlm_ls_release, .default_groups = dlm_groups, .sysfs_ops = &dlm_attr_ops, };
@@ -355,6 +363,8 @@ static void free_lockspace(struct work_struct *work)*/ rhashtable_free_and_destroy (&ls->ls_rsbtbl, rhash_free_rsb,NULL ); +kobject_put (&ls->ls_kobj); +wait_for_completion (&ls->ls_kobj_done);kfree (ls); }
@@ -435,7 +445,10 @@ static int new_lockspace(const char *name, const char *cluster, ls->ls_lvblen = lvblen;atomic_set (&ls->ls_count,0 );init_waitqueue_head (&ls->ls_count_wait); +init_completion (&ls->ls_kobj_done); ls->ls_flags =0 ; + ls->ls_kobj.kset = dlm_kset; +kobject_init (&ls->ls_kobj, &dlm_ktype);if (ops && dlm_config.ci_recover_callbacks) { ls->ls_ops = ops;
@@ -567,9 +580,7 @@ static int new_lockspace(const char *name, const char *cluster,wait_event (ls->ls_recover_lock_wait,test_bit (LSFL_RECOVER_LOCK , &ls->ls_flags)); - ls->ls_kobj.kset = dlm_kset; - error =kobject_init_and_add (&ls->ls_kobj, &dlm_ktype,NULL , -"%s" , ls->ls_name); + error =kobject_add (&ls->ls_kobj,NULL ,"%s" , ls->ls_name);if (error) goto out_recoverd;kobject_uevent (&ls->ls_kobj,KOBJ_ADD );
@@ -582,7 +593,7 @@ static int new_lockspace(const char *name, const char *cluster, error =do_uevent (ls,1 ,0 );if (error <0 ) - goto out_recoverd; + goto out_kobj;/* wait until recovery is successful or failed */ wait_for_completion (&ls->ls_recovery_done);
@@ -600,6 +611,8 @@ static int new_lockspace(const char *name, const char *cluster,do_uevent (ls,0 ,0 );dlm_clear_members (ls);kfree (ls->ls_node_array); + out_kobj: +kobject_del (&ls->ls_kobj); out_recoverd:dlm_recoverd_stop (ls); out_callback:
@@ -615,6 +628,7 @@ static int new_lockspace(const char *name, const char *cluster,rhashtable_destroy (&ls->ls_rsbtbl); out_lsfree:kobject_put (&ls->ls_kobj); +wait_for_completion (&ls->ls_kobj_done);kfree (ls); out:module_put (THIS_MODULE );
@@ -740,6 +754,8 @@ static int release_lockspace(struct dlm_ls *ls, unsigned int release_option) dlm_user_daemon_available())do_uevent (ls,0 , (release_option ==DLM_RELEASE_RECOVER )); +kobject_del (&ls->ls_kobj); +dlm_recoverd_stop (ls);/* clear the LSFL_RUNNING flag to fast up
@@ -759,8 +775,6 @@ static int release_lockspace(struct dlm_ls *ls, unsigned int release_option)dlm_delete_debug_file (ls); -kobject_put (&ls->ls_kobj); -xa_destroy (&ls->ls_recover_xa);kfree (ls->ls_recover_buf);
Signature · 1 line
2.56.0.455.g6c5a503b38-goog
PATCH v3 6/9 xen/sys-hypervisor: Add release callback to hyp_sysfs_kobj_type
In reply to Ian Rogershypervisor_init() in drivers/base/hypervisor.c creates hypervisor_kobj with kobject_create_and_add() (which allocates a dynamic kobject using dynamic_kobj_ktype), and hypervisor_subsys_init() in drivers/xen/sys-hypervisor.c then overwrites hypervisor_kobj->ktype with &hyp_sysfs_kobj_type, which had no .release callback.
Add hyp_sysfs_release() calling kfree(kobj) to preserve the dynamic kobject release behavior.
--- drivers/xen/sys-hypervisor.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/xen/sys-hypervisor.c +6 -0
@@ -659,7 +659,13 @@ static const struct sysfs_ops hyp_sysfs_ops = { .store = hyp_sysfs_store, }; +static void hyp_sysfs_release (struct kobject *kobj) +{ +kfree (kobj); +} +static const struct kobj_type hyp_sysfs_kobj_type = { + .release = hyp_sysfs_release, .sysfs_ops = &hyp_sysfs_ops, };
Signature · 1 line
2.56.0.455.g6c5a503b38-goog
PATCH v3 7/9 ubifs: sysfs: Use kset_create_and_add() for ubifs_kset
In reply to Ian Rogersubifs_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().
--- fs/ubifs/sysfs.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-)
fs/ubifs/sysfs.c +7 -17
@@ -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); }
Signature · 1 line
2.56.0.455.g6c5a503b38-goog
PATCH v3 8/9 drm/amdkfd: Free queue in procfs_queue_type kobject release callback
In reply to Ian Rogersstruct queue embeds a struct kobject (q->kobj) for procfs entries, but procfs_queue_type had no .release callback and uninit_queue() freed q immediately after kfd_procfs_del_queue() called kobject_put(&q->kobj). With CONFIG_DEBUG_KOBJECT_RELEASE=y, this causes a use-after-free.
Add kfd_procfs_queue_release() to free struct queue from the kobject release callback, change kfd_procfs_del_queue() to only remove the kobject from sysfs via kobject_del(), and drop the final reference in uninit_queue() via kobject_put(). Check q->kobj.state_in_sysfs before calling kobject_del() in kfd_procfs_del_queue() to avoid warnings if sysfs creation previously failed.
--- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 12 +++++++++--- drivers/gpu/drm/amd/amdkfd/kfd_queue.c | 5 ++++- 2 files changed, 13 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_process.c +9 -3
@@ -512,7 +512,15 @@ static const struct sysfs_ops procfs_queue_ops = { .show = kfd_procfs_queue_show, }; +static void kfd_procfs_queue_release (struct kobject *kobj) +{ + struct queue *q = container_of(kobj, struct queue, kobj); + +kfree (q); +} +static const struct kobj_type procfs_queue_type = { + .release = kfd_procfs_queue_release, .sysfs_ops = &procfs_queue_ops, .default_groups = procfs_queue_groups, };
@@ -552,7 +560,6 @@ int kfd_procfs_add_queue(struct queue *q)if (ret <0 ) {pr_warn ("Creating proc/<pid>/queues/%u failed" , q->properties.queue_id); -kobject_put (&q->kobj);return ret; }
@@ -697,11 +704,10 @@ static void kfd_procfs_add_sysfs_files(struct kfd_process *p)void kfd_procfs_del_queue (struct queue *q) { -if (!q || !q->process->kobj) +if (!q || !q->process || !q->process->kobj || !q->kobj.state_in_sysfs)return ;kobject_del (&q->kobj); -kobject_put (&q->kobj); }int kfd_process_create_wq (void )
drivers/gpu/drm/amd/amdkfd/kfd_queue.c +4 -1
@@ -83,7 +83,10 @@ int init_queue(struct queue **q, const struct queue_properties *properties)void uninit_queue (struct queue *q) { -kfree (q); +if (q && q->kobj.state_initialized) +kobject_put (&q->kobj); +else +kfree (q); }#if IS_ENABLED (CONFIG_HSA_AMD_SVM )
Signature · 1 line
2.56.0.455.g6c5a503b38-goog
PATCH v3 9/9 kobject: Require explicit initialization of struct kobj_type::release
In reply to Ian RogersDocumentation/core-api/kobject.rst states:
"One important point cannot be overstated: every kobject must have a release() method, and the kobject must persist (in a consistent state) until that method is called. If these constraints are not met, the code is flawed. Note that the kernel will warn you if you forget to provide a release() method. Do not try to get rid of this warning by providing an \"empty\" release function."
Annotate struct kobj_type::release with __must_init so the compiler diagnoses any struct kobj_type initializer that omits .release.
For the remaining legacy struct kobj_type definitions where the kobject is static, per-CPU, a permanent firmware structure, or embedded inside a devm- or parent-managed allocation rather than freed by kobject_put(), explicitly initialize .release = NULL with a comment documenting why no release callback is provided.
Many of these legacy sites are not safe with CONFIG_DEBUG_KOBJECT_RELEASE (for example when backing memory is freed, zeroed, or unmapped on module unload while delayed kobject cleanup is still pending). Fixing those lifetimes is left to follow-up patches; this change does not alter their behavior.
--- arch/arm64/kernel/cpuinfo.c | 5 +++++ drivers/acpi/sysfs.c | 2 ++ drivers/dma/ioat/sysfs.c | 7 +++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 5 +++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 10 +++++++++ drivers/infiniband/hw/hfi1/sysfs.c | 5 +++++ drivers/infiniband/hw/usnic/usnic_ib_sysfs.c | 5 +++++ drivers/parisc/pdc_stable.c | 5 +++++ drivers/power/supply/ab8500_fg.c | 5 +++++ drivers/s390/char/sclp_mem.c | 2 ++ drivers/soc/hisilicon/kunpeng_hccs.c | 21 +++++++++++++++++++ .../fbdev/omap2/omapfb/dss/display-sysfs.c | 7 +++++++ .../fbdev/omap2/omapfb/dss/manager-sysfs.c | 8 +++++++ .../fbdev/omap2/omapfb/dss/overlay-sysfs.c | 8 +++++++ fs/erofs/sysfs.c | 10 +++++++++ fs/f2fs/sysfs.c | 15 +++++++++++++ fs/ocfs2/cluster/masklog.c | 5 +++++ include/linux/kobject.h | 2 +- 18 files changed, 126 insertions(+), 1 deletion(-)
arch/arm64/kernel/cpuinfo.c +5 -0
@@ -295,6 +295,11 @@ const struct seq_operations cpuinfo_op = {static const struct kobj_type cpuregs_kobj_type = { +/* +* Pre-existing: info->kobj is embedded in per-CPU cpu_data; +* cpuid_cpu_offline() only calls kobject_del(). +*/ + .release =NULL , .sysfs_ops = &kobj_sysfs_ops, };
drivers/acpi/sysfs.c +2 -0
@@ -975,6 +975,8 @@ static struct attribute *hotplug_profile_attrs[] = {ATTRIBUTE_GROUPS (hotplug_profile);static const struct kobj_type acpi_hotplug_profile_ktype = { +/* Pre-existing: hotplug->kobj is embedded in static struct acpi_scan_hotplug objects. */ + .release =NULL , .sysfs_ops = &kobj_sysfs_ops, .default_groups = hotplug_profile_groups, };
drivers/dma/ioat/sysfs.c +7 -0
@@ -167,6 +167,13 @@ static const struct attribute *const ioat_attrs[] = {ATTRIBUTE_GROUPS (ioat);const struct kobj_type ioat_ktype = { +/* +* Pre-existing: ioatdma_chan is freed by release_ioatdma(), not +* by kobject_put(). With CONFIG_DEBUG_KOBJECT_RELEASE the delayed +* kobject cleanup queued by ioat_kobject_del() may run after +* that kfree(), a use-after-free. +*/ + .release =NULL , .sysfs_ops = &ioat_sysfs_ops, .default_groups = ioat_groups, };
drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c +5 -0
@@ -892,6 +892,11 @@ static const struct attribute_group ualink_xcp_info_group = { };static const struct kobj_type ualink_xcp_info_ktype = { +/* +* Pre-existing: xcp->ualink.kobj is embedded in struct amdgpu_xcp_mgr +* rather than freed individually by kobject_put(). +*/ + .release =NULL , .sysfs_ops = &kobj_sysfs_ops };
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +10 -0
@@ -797,6 +797,11 @@ static const struct sysfs_ops xcp_cfg_res_sysfs_ops = { };static const struct kobj_type xcp_cfg_res_sysfs_ktype = { +/* +* Pre-existing: xcp_res is embedded in struct amdgpu_xcp_cfg +* rather than freed individually by kobject_put(). +*/ + .release =NULL , .sysfs_ops = &xcp_cfg_res_sysfs_ops, .default_groups = xcp_cfg_res_sysfs_groups, };
@@ -1061,6 +1066,11 @@ static const struct attribute_group amdgpu_xcp_attrs_group = { };static const struct kobj_type xcp_sysfs_ktype = { +/* +* Pre-existing: xcp is embedded in struct amdgpu_xcp_mgr +* rather than freed individually by kobject_put(). +*/ + .release =NULL , .sysfs_ops = &kobj_sysfs_ops, };
drivers/infiniband/hw/hfi1/sysfs.c +5 -0
@@ -608,6 +608,11 @@ static const struct sysfs_ops sde_sysfs_ops = { };static struct kobj_type sde_ktype = { +/* +* Pre-existing: sdma_engine is embedded in dd->per_sdma array +* rather than freed by kobject_put(). +*/ + .release =NULL , .sysfs_ops = &sde_sysfs_ops, };
drivers/infiniband/hw/usnic/usnic_ib_sysfs.c +5 -0
@@ -245,6 +245,11 @@ static struct attribute *usnic_ib_qpn_default_attrs[] = {ATTRIBUTE_GROUPS (usnic_ib_qpn_default);static struct kobj_type usnic_ib_qpn_type = { +/* +* Pre-existing: qp_grp->kobj is embedded in RDMA core-managed +* struct usnic_ib_qp_grp rather than freed by kobject_put(). +*/ + .release =NULL , .sysfs_ops = &usnic_ib_qpn_sysfs_ops, .default_groups = usnic_ib_qpn_default_groups, };
drivers/parisc/pdc_stable.c +5 -0
@@ -484,6 +484,11 @@ ATTRIBUTE_GROUPS(paths_subsys);/* Specific kobject type for our PDC paths */ static const struct kobj_type ktype_pdcspath = { +/* +* Pre-existing: pdcspath_entry instances are static; lifetime +* is not controlled by kobject_put(). +*/ + .release =NULL , .sysfs_ops = &pdcspath_attr_ops, .default_groups = paths_subsys_groups, };
drivers/power/supply/ab8500_fg.c +5 -0
@@ -2539,6 +2539,11 @@ static struct attribute *ab8500_fg_attrs[] = {ATTRIBUTE_GROUPS (ab8500_fg);static const struct kobj_type ab8500_fg_ktype = { +/* +* Pre-existing: fg_kobject is embedded in devm-allocated struct +* ab8500_fg; ab8500_fg_sysfs_exit() only calls kobject_del(). +*/ + .release =NULL , .sysfs_ops = &ab8500_fg_sysfs_ops, .default_groups = ab8500_fg_groups, };
drivers/s390/char/sclp_mem.c +2 -0
@@ -305,6 +305,8 @@ static ssize_t sclp_memmap_on_memory_store(struct kobject *kobj, struct kobj_att }static const struct kobj_type ktype = { +/* Pre-existing: permanent firmware kobjects, never freed */ + .release =NULL , .sysfs_ops = &kobj_sysfs_ops, };
drivers/soc/hisilicon/kunpeng_hccs.c +21 -0
@@ -1038,6 +1038,13 @@ static struct attribute *hccs_port_default_attrs[] = {ATTRIBUTE_GROUPS (hccs_port_default);static const struct kobj_type hccs_port_type = { +/* +* Pre-existing: hccs_port_info is allocated via devm_kzalloc() +* rather than freed by kobject_put(). With +* CONFIG_DEBUG_KOBJECT_RELEASE the delayed kobject cleanup may run +* after devm frees it on unbind, a use-after-free. +*/ + .release =NULL , .sysfs_ops = &hccs_comm_ops, .default_groups = hccs_port_default_groups, };
@@ -1110,6 +1117,13 @@ static struct attribute *hccs_die_default_attrs[] = {ATTRIBUTE_GROUPS (hccs_die_default);static const struct kobj_type hccs_die_type = { +/* +* Pre-existing: hccs_die_info is allocated via devm_kzalloc() +* rather than freed by kobject_put(). With +* CONFIG_DEBUG_KOBJECT_RELEASE the delayed kobject cleanup may run +* after devm frees it on unbind, a use-after-free. +*/ + .release =NULL , .sysfs_ops = &hccs_comm_ops, .default_groups = hccs_die_default_groups, };
@@ -1213,6 +1227,13 @@ static struct attribute *hccs_chip_default_attrs[] = {ATTRIBUTE_GROUPS (hccs_chip_default);static const struct kobj_type hccs_chip_type = { +/* +* Pre-existing: hccs_chip_info is allocated via devm_kzalloc() +* rather than freed by kobject_put(). With +* CONFIG_DEBUG_KOBJECT_RELEASE the delayed kobject cleanup may run +* after devm frees it on unbind, a use-after-free. +*/ + .release =NULL , .sysfs_ops = &hccs_comm_ops, .default_groups = hccs_chip_default_groups, };
drivers/video/fbdev/omap2/omapfb/dss/display-sysfs.c +7 -0
@@ -304,6 +304,13 @@ static const struct sysfs_ops display_sysfs_ops = { };static struct kobj_type display_ktype = { +/* +* Pre-existing: dssdev->kobj is embedded in struct omap_dss_device +* and zeroed in display_uninit_sysfs() right after kobject_put(). +* With CONFIG_DEBUG_KOBJECT_RELEASE that memset() clobbers the +* pending delayed kobject cleanup. +*/ + .release =NULL , .sysfs_ops = &display_sysfs_ops, .default_groups = display_sysfs_groups, };
drivers/video/fbdev/omap2/omapfb/dss/manager-sysfs.c +8 -0
@@ -496,6 +496,14 @@ static const struct sysfs_ops manager_sysfs_ops = { };static struct kobj_type manager_ktype = { +/* +* Pre-existing: mgr->kobj is embedded in dynamically allocated +* managers[], zeroed in dss_manager_kobj_uninit() right after +* kobject_put(), and freed in dss_uninit_overlay_managers(). With +* CONFIG_DEBUG_KOBJECT_RELEASE that clobbers and frees the pending +* delayed kobject cleanup. +*/ + .release =NULL , .sysfs_ops = &manager_sysfs_ops, .default_groups = manager_sysfs_groups, };
drivers/video/fbdev/omap2/omapfb/dss/overlay-sysfs.c +8 -0
@@ -429,6 +429,14 @@ static const struct sysfs_ops overlay_sysfs_ops = { };static struct kobj_type overlay_ktype = { +/* +* Pre-existing: ovl->kobj is embedded in dynamically allocated +* overlays[] and freed in dss_uninit_overlays() right after +* dss_overlay_kobj_uninit() calls kobject_put(). With +* CONFIG_DEBUG_KOBJECT_RELEASE the delayed kobject cleanup may run +* after kfree(overlays), a use-after-free. +*/ + .release =NULL , .sysfs_ops = &overlay_sysfs_ops, .default_groups = overlay_sysfs_groups, };
fs/erofs/sysfs.c +10 -0
@@ -238,6 +238,11 @@ static const struct kobj_type erofs_sb_ktype = {static const struct kobj_type erofs_ktype = { .default_groups = erofs_groups, .sysfs_ops = &erofs_attr_ops, +/* +* Pre-existing: erofs_root is a static struct kset; lifetime +* is not controlled by kobject_put(). +*/ + .release =NULL , };static struct kset erofs_root = {
@@ -247,6 +252,11 @@ static struct kset erofs_root = {static const struct kobj_type erofs_feat_ktype = { .default_groups = erofs_feat_groups, .sysfs_ops = &erofs_attr_ops, +/* +* Pre-existing: erofs_feat is a static struct kobject; lifetime +* is not controlled by kobject_put(). +*/ + .release =NULL , };static struct kobject erofs_feat = {
fs/f2fs/sysfs.c +15 -0
@@ -1683,6 +1683,11 @@ static const struct kobj_type f2fs_sb_ktype = {static const struct kobj_type f2fs_ktype = { .sysfs_ops = &f2fs_attr_ops, +/* +* Pre-existing: f2fs_kset is a static struct kset; lifetime +* is not controlled by kobject_put(). +*/ + .release =NULL , };static struct kset f2fs_kset = {
@@ -1697,6 +1702,11 @@ static const struct sysfs_ops f2fs_feat_attr_ops = {static const struct kobj_type f2fs_feat_ktype = { .default_groups = f2fs_feat_groups, .sysfs_ops = &f2fs_feat_attr_ops, +/* +* Pre-existing: f2fs_feat is a static struct kobject; lifetime +* is not controlled by kobject_put(). +*/ + .release =NULL , };static struct kobject f2fs_feat = {
@@ -1711,6 +1721,11 @@ static const struct sysfs_ops f2fs_tune_attr_ops = {static const struct kobj_type f2fs_tune_ktype = { .default_groups = f2fs_tune_groups, .sysfs_ops = &f2fs_tune_attr_ops, +/* +* Pre-existing: f2fs_tune is a static struct kobject; lifetime +* is not controlled by kobject_put(). +*/ + .release =NULL , };static struct kobject f2fs_tune = {
fs/ocfs2/cluster/masklog.c +5 -0
@@ -147,6 +147,11 @@ static const struct sysfs_ops mlog_attr_ops = {static struct kobj_type mlog_ktype = { .default_groups = mlog_default_groups, .sysfs_ops = &mlog_attr_ops, +/* +* Pre-existing: mlog_kset is a static struct kset; lifetime +* is not controlled by kobject_put(). +*/ + .release =NULL , };static struct kset mlog_kset = {
include/linux/kobject.h +1 -1
@@ -114,7 +114,7 @@ void kobject_get_ownership(const struct kobject *kobj, kuid_t *uid, kgid_t *gid)char *kobject_get_path (const struct kobject *kobj,gfp_t flag);struct kobj_type { -void (*release)(struct kobject *kobj); + void (*release)(struct kobject *kobj) __must_init;const struct sysfs_ops *sysfs_ops;const struct attribute_group **default_groups;const struct kobj_ns_type_operations *(*child_ns_type)(const struct kobject *kobj);
Signature · 1 line
2.56.0.455.g6c5a503b38-goog
[email protected]
AI reviewRe: [PATCH v3 1/9] Compiler Attributes: Add __must_init macro
In reply to Ian RogersSashiko has reviewed this patch and found no issues.
Quoted 15 lines
Clang supports the '
require_explicit_initialization' attribute on struct fields to indicate that a field must be initialized explicitly by the user when the object is constructed. When an aggregate initializer or uninitialized variable omits an annotated field, Clang emits a -Wuninitialized-explicit-init warning (enabled by default).Add the
__must_initmacro toinclude/linux/compiler_attributes.h(which is included byinclude/linux/compiler_types.handinclude/linux/compiler.h) so kernel structs with error-prone initialization (such as mandatory callbacks or cleanup handlers) can enforce explicit initialization at compile time, as discussed at the Linux Plumbers Conference. The shorter__must_initspelling, rather than the attribute's full name, keeps annotated struct members readable and was suggested by Greg Kroah-Hartman.
Quoted 6 lines
[ ... ]Reviewed-by Nick Desaulniers <[email protected]>Reviewed-by Nathan Chancellor <[email protected]>Reviewed-by Kees Cook <[email protected]>Signed-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH v3 2/9] powerpc/secvar: Add missing kobject release callback to secvar_ktype
In reply to Ian RogersSashiko has reviewed this patch and found no issues.
Quoted 11 lines
In
add_var(), a struct kobject is dynamically allocated withkzalloc_obj()and initialized withsecvar_ktype. Ifkobject_add()orsysfs_create_file()fails,kobject_put(kobj)is called to clean up. However,secvar_ktypedoes not define a .release callback, which results in a memory leak of kobj (and apr_debugwarning inkobject_cleanup()whenCONFIG_DEBUG_KOBJECT_RELEASEis enabled).Provide a
secvar_release()callback that calls kfree(kobj).Fixes bd5d9c743d38 ("powerpc: expose secure variables to userspace via sysfs")Signed-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH v3 3/9] sh: sq: Add missing kobject release callback to ktype_percpu_entry
In reply to Ian RogersSashiko has reviewed this patch and found no issues.
Quoted 9 lines
In
sq_dev_add(), sq_kobject[cpu] is dynamically allocated withkzalloc_obj()and initialized withktype_percpu_entry. Whensq_dev_remove()callskobject_put(kobj), the kobject is never freed becausektype_percpu_entrylacks a .release callback.Provide a
sq_kobj_release()callback that calls kfree(kobj).Fixes d7c30c682a27 ("sh: Store Queue API rework.")Signed-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH v3 4/9] cpufreq: governor: Initialize kobj_type release callback statically
In reply to Ian RogersSashiko has reviewed this patch and found no issues.
Quoted 11 lines
Export
cpufreq_dbs_data_release()and initialize .kobj_type.release statically in the ondemand and conservative governors instead of assigning it at runtime incpufreq_dbs_governor_init().This prepares for annotating struct
kobj_type::releasewith__must_init.Reviewed-by Zhongqiu Han <[email protected]>Acked-by Viresh Kumar <[email protected]>Signed-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH v3 5/9] dlm: Free dlm_ls in kobject release callback
In reply to Ian RogersThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] dlm: wrong Fixes commit and misleading subject for dlm_ls_release() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] dlm: wrong Fixes commit and misleading subject for dlm_ls_release()
--
commit cebf1bf6f5d4b67423eada980e5a294abe491cc6
Author: Ian Rogers <[email protected]>
Quoted 16 lines
dlm: Free
dlm_lsin kobject release callbackstruct
dlm_lsembeds a struct kobject (ls_kobj), butdlm_ktypelacked a .release callback and dlm freed the lockspace structure directly via kfree(ls). WithCONFIG_DEBUG_KOBJECT_RELEASE=y, freeing ls before the delayed kobject release runs causes a use-after-free, and unloading the module while the delayed release is pending results in an instruction page fault.Add a completion
ls_kobj_doneanddlm_ls_release()to complete it when the last kobject reference is dropped, waiting for it infree_lockspace()before kfree(ls) and in thenew_lockspace()error path beforemodule_put(). Also delete the kobject viakobject_del()before stoppingdlm_recoverdto close the window where concurrent sysfs writes could wake the stopped recovery task.
Quoted 3 lines
Fixes 3514faca19a6 ("kobject: remove struct kobj_type from struct kset")Acked-by Alexander Aring <[email protected]>Signed-off-by Ian Rogers <[email protected]>
[Severity: Low]3514faca19a6 ("kobject: remove struct kobj_type from struct kset") only removed the .ktype pointer from dlm_kset while leaving dlm_ktype.release set to lockspace_kobj_release(). The commit that dropped the release callback from dlm_ktype and started calling kfree(ls) directly after kobject_put(&ls->ls_kobj) is 8a4cf500f1dd ("dlm: drop kobject release callback handling"). Should the Fixes: tag point to that commit instead:
Also, the subject line says dlm_ls is freed in the kobject release callback, whereas dlm_ls_release() only signals ls_kobj_done and kfree(ls) Still happens in free_lockspace() and new_lockspace().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
[email protected]
AI reviewRe: [PATCH v3 6/9] xen/sys-hypervisor: Add release callback to hyp_sysfs_kobj_type
In reply to Ian RogersSashiko has reviewed this patch and found no issues.
Quoted 11 lines
hypervisor_init()indrivers/base/hypervisor.ccreateshypervisor_kobjwithkobject_create_and_add()(which allocates a dynamic kobject usingdynamic_kobj_ktype), andhypervisor_subsys_init()indrivers/xen/sys-hypervisor.cthen overwriteshypervisor_kobj->ktypewith&hyp_sysfs_kobj_type, which had no .release callback.Add
hyp_sysfs_release()calling kfree(kobj) to preserve the dynamic kobject release behavior.Fixes cff7e81b3dd7 ("xen: add /sys/hypervisor support")Signed-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
[email protected]
AI reviewRe: [PATCH v3 7/9] ubifs: sysfs: Use kset_create_and_add() for ubifs_kset
In reply to Ian RogersThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] ubifs: sysfs: inaccurate Fixes trailer in commit message --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] ubifs: sysfs: inaccurate Fixes trailer in commit message --
commit 05ad573fa4719a7a6e36bb8dcf3c9060b5c194b0
Author: Ian Rogers <[email protected]>
Quoted 7 lines
ubifs: sysfs: Use
kset_create_and_add()forubifs_kset
ubifs_ksetwas a static struct kset using a customubifs_ktypethat had nodefault_groupsand no .release callback. WithCONFIG_DEBUG_KOBJECT_RELEASE=y, unloading the ubifs module while delayed kobject release is pending causes a use-after-free on the static kset.
Quoted 7 lines
Replace the static
ubifs_ksetand emptyubifs_ktypewith a dynamically allocated kset viakset_create_and_add().Fixes 203a55f04f66 ("ubifs: Fix memory leak in ubifs_sysfs_init()")Tested-by Zhihao Cheng <[email protected]>Reviewed-by Zhihao Cheng <[email protected]>Signed-off-by Ian Rogers <[email protected]>
[Severity: Low]203a55f04f66 ("ubifs: Fix memory leak in ubifs_sysfs_init()") only added an error-path kset_put() when kset_register() fails. The static ubifs_kset, ubifs_ktype without a release callback, and kset_unregister() on module exit were introduced in 2e3cbf425804 ("ubifs: Export filesystem error counters").
Should the Fixes tag instead be:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
[email protected]
AI reviewRe: [PATCH v3 8/9] drm/amdkfd: Free queue in procfs_queue_type kobject release callback
In reply to Ian RogersSashiko has reviewed this patch and found no issues.
Quoted 12 lines
struct queue embeds a struct kobject (
q->kobj) for procfs entries, butprocfs_queue_typehad no .release callback anduninit_queue()freed q immediately afterkfd_procfs_del_queue()calledkobject_put(&q->kobj). WithCONFIG_DEBUG_KOBJECT_RELEASE=y, this causes a use-after-free.Add
kfd_procfs_queue_release()to free struct queue from the kobject release callback, changekfd_procfs_del_queue()to only remove the kobject from sysfs viakobject_del(), and drop the final reference inuninit_queue()viakobject_put(). Checkq->kobj.state_in_sysfsbefore callingkobject_del()inkfd_procfs_del_queue()to avoid warnings if sysfs creation previously failed.
Quoted 3 lines
Fixes 6d220a7e7971 ("drm/amdkfd: Add queue information to sysfs")Reviewed-by Felix Kuehling <[email protected]>Signed-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
[email protected]
AI reviewRe: [PATCH v3 9/9] kobject: Require explicit initialization of struct kobj_type::release
In reply to Ian RogersSashiko has reviewed this patch and found no issues.
Quoted 18 lines
Documentation/core-api/kobject.rststates:"One important point cannot be overstated: every kobject must have a
release()method, and the kobject must persist (in a consistent state) until that method is called. If these constraints are not met, the code is flawed. Note that the kernel will warn you if you forget to provide arelease()method. Do not try to get rid of this warning by providing an \"empty\" release function."Annotate struct
kobj_type::releasewith__must_initso the compiler diagnoses any structkobj_typeinitializer that omits .release.For the remaining legacy struct
kobj_typedefinitions where the kobject is static, per-CPU, a permanent firmware structure, or embedded inside a devm- or parent-managed allocation rather than freed bykobject_put(), explicitly initialize .release = NULL with a comment documenting why no release callback is provided.
Quoted 8 lines
Many of these legacy sites are not safe with
CONFIG_DEBUG_KOBJECT_RELEASE(for example when backing memory is freed, zeroed, or unmapped on module unload while delayed kobject cleanup is still pending). Fixing those lifetimes is left to follow-up patches; this change does not alter their behavior.
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Re: [PATCH v3 6/9] xen/sys-hypervisor: Add release callback to hyp_sysfs_kobj_type
In reply to Ian RogersQuoted 23 lines · Ian Rogers
hypervisor_init()indrivers/base/hypervisor.ccreateshypervisor_kobjwithkobject_create_and_add()(which allocates a dynamic kobject usingdynamic_kobj_ktype), andhypervisor_subsys_init()indrivers/xen/sys-hypervisor.cthen overwriteshypervisor_kobj->ktypewith&hyp_sysfs_kobj_type, which had no .release callback.Add
hyp_sysfs_release()calling kfree(kobj) to preserve the dynamic kobject release behavior.Fixes cff7e81b3dd7 ("xen: add /sys/hypervisor support")Signed-off-by Ian Rogers <[email protected]>--- drivers/xen/sys-hypervisor.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/xen/sys-hypervisor.c +0
-0@@ -659,7 +659,13 @@ static const struct sysfs_ops hyp_sysfs_ops = { .store = hyp_sysfs_store, };
drivers/xen/sys-hypervisor.c static const struct sysfs_ops hyp_sysfs_ops = { · line 671
Quoted 10 lines
drivers/xen/sys-hypervisor.c +6
-0+static void hyp_sysfs_release (struct kobject *kobj) +{ +kfree (kobj); +} +static const struct kobj_type hyp_sysfs_kobj_type = { + .release = hyp_sysfs_release, .sysfs_ops = &hyp_sysfs_ops, };
Wouldn't it make sense to have a common function for just kfree(kobj)?
In your series there are 3 instances of .release just doing kfree(kobj).
In case this is not wanted or with using the suggested common .release helper you can add my
Juergen
Re: [PATCH v3 6/9] xen/sys-hypervisor: Add release callback to hyp_sysfs_kobj_type
Quoted 38 lines · Juergen Gross
Quoted 23 lines · Ian Rogers
hypervisor_init()indrivers/base/hypervisor.ccreateshypervisor_kobjwithkobject_create_and_add()(which allocates a dynamic kobject usingdynamic_kobj_ktype), andhypervisor_subsys_init()indrivers/xen/sys-hypervisor.cthen overwriteshypervisor_kobj->ktypewith&hyp_sysfs_kobj_type, which had no .release callback.Add
hyp_sysfs_release()calling kfree(kobj) to preserve the dynamic kobject release behavior.Fixes cff7e81b3dd7 ("xen: add /sys/hypervisor support")Signed-off-by Ian Rogers <[email protected]>--- drivers/xen/sys-hypervisor.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/xen/sys-hypervisor.c +0
-0@@ -659,7 +659,13 @@ static const struct sysfs_ops hyp_sysfs_ops = { .store = hyp_sysfs_store, };drivers/xen/sys-hypervisor.c static const struct sysfs_ops hyp_sysfs_ops = { · line 671
Quoted 10 lines
drivers/xen/sys-hypervisor.c +6
-0+static void hyp_sysfs_release (struct kobject *kobj) +{ +kfree (kobj); +} +static const struct kobj_type hyp_sysfs_kobj_type = { + .release = hyp_sysfs_release, .sysfs_ops = &hyp_sysfs_ops, };Wouldn't it make sense to have a common function for just kfree(kobj)?
Quoted 6 lines
In your series there are 3 instances of .release just doing kfree(kobj).
In case this is not wanted or with using the suggested common .release helper you can add my
Reviewed-by Juergen Gross <[email protected]>
Thanks Juergen!
lib/kobject.c already has a static dynamic_kobj_release() that does this (and there are ~15 other places in the tree open-coding a static kfree(kobj) release wrapper), so include/linux/kobject.h + lib/kobject.c would be the natural home if we exported one.
I kept them as local static functions here for two reasons:
1. Patches 2/9, 3/9, and 6/9 carry Fixes: tags, and keeping the small local callbacks avoids a dependency on a new driver-core export for backports.
2. Since kobjects are normally embedded in a larger struct and freed via container_of(), I wasn't sure whether Greg and Danilo would view an exported kfree(kobj) release helper (especially alongside __must_init) as an invitation for misuse on embedded kobjects.
Unless Greg or Danilo would like dynamic_kobj_release() (or similar) exported now, I'll plan to keep the local callbacks for this series and can send a follow-up cleanup for the tree-wide callers if driver-core maintainers think a shared helper makes sense.
Thanks,
Ian
Quoted 3 lines
Juergen
Re: [PATCH v3 2/9] powerpc/secvar: Add missing kobject release callback to secvar_ktype
In reply to Ian RogersQuoted 8 lines · Ian Rogers
In
add_var(), a struct kobject is dynamically allocated withkzalloc_obj()and initialized withsecvar_ktype. Ifkobject_add()orsysfs_create_file()fails,kobject_put(kobj)is called to clean up. However,secvar_ktypedoes not define a .release callback, which results in a memory leak of kobj (and apr_debugwarning inkobject_cleanup()whenCONFIG_DEBUG_KOBJECT_RELEASEis enabled).
Quoted 4 lines
Provide a
secvar_release()callback that calls kfree(kobj).Fixes bd5d9c743d38 ("powerpc: expose secure variables to userspace via sysfs")Signed-off-by Ian Rogers <[email protected]>
Gentle ping on this patch (moving PowerPC maintainers to To: in case this got buried in Cc:).
Danilo offered to take the full 9-patch kobj_type::release __must_init series through the driver-core tree with subsystem ACKs, and this is one of the last two patches awaiting an Acked-by. Does this look okay to go via driver-core?
Thanks,
Ian
Quoted 25 lines
--- arch/powerpc/kernel/secvar-sysfs.c | 6 ++++++ 1 file changed, 6 insertions(+)arch/powerpc/kernel/secvar-sysfs.c +6
-1@@ -126,7 +126,13 @@ static const struct attribute_group secvar_attr_group = { };__ATTRIBUTE_GROUPS (secvar_attr); +static void secvar_release (struct kobject *kobj) +{ +kfree (kobj); +} +static const struct kobj_type secvar_ktype = { + .release = secvar_release, .sysfs_ops = &kobj_sysfs_ops, .default_groups = secvar_attr_groups, }; --2.56.0.455.g6c5a503b38-goog
Re: [PATCH v3 3/9] sh: sq: Add missing kobject release callback to ktype_percpu_entry
In reply to Ian RogersQuoted 10 lines · Ian Rogers
In
sq_dev_add(), sq_kobject[cpu] is dynamically allocated withkzalloc_obj()and initialized withktype_percpu_entry. Whensq_dev_remove()callskobject_put(kobj), the kobject is never freed becausektype_percpu_entrylacks a .release callback.Provide a
sq_kobj_release()callback that calls kfree(kobj).Fixes d7c30c682a27 ("sh: Store Queue API rework.")Signed-off-by Ian Rogers <[email protected]>
Gentle ping on this patch (moving SuperH maintainers to To: in case this got buried in Cc:).
Danilo offered to take the full 9-patch kobj_type::release __must_init series through the driver-core tree with subsystem ACKs, and this is one of the last two patches awaiting an Acked-by. Does this look okay to go via driver-core?
Thanks,
Ian
Quoted 25 lines
--- arch/sh/kernel/cpu/sh4/sq.c | 6 ++++++ 1 file changed, 6 insertions(+)arch/sh/kernel/cpu/sh4/sq.c +6
-1@@ -331,7 +331,13 @@ static const struct sysfs_ops sq_sysfs_ops = { .store = sq_sysfs_store, }; +static void sq_kobj_release (struct kobject *kobj) +{ +kfree (kobj); +} +static struct kobj_type ktype_percpu_entry = { + .release = sq_kobj_release, .sysfs_ops = &sq_sysfs_ops, .default_groups = sq_sysfs_groups, }; --2.56.0.455.g6c5a503b38-goog
John Paul Adrian Glaubitz
maintainerRe: [PATCH v3 3/9] sh: sq: Add missing kobject release callback to ktype_percpu_entry
Hi Ian,
Quoted 12 lines · Ian Rogers
Quoted 10 lines · Ian Rogers
In
sq_dev_add(), sq_kobject[cpu] is dynamically allocated withkzalloc_obj()and initialized withktype_percpu_entry. Whensq_dev_remove()callskobject_put(kobj), the kobject is never freed becausektype_percpu_entrylacks a .release callback.Provide a
sq_kobj_release()callback that calls kfree(kobj).Fixes d7c30c682a27 ("sh: Store Queue API rework.")Signed-off-by Ian Rogers <[email protected]>
Quoted 7 lines
Gentle ping on this patch (moving SuperH maintainers to To: in case this got buried in Cc:).
Danilo offered to take the full 9-patch
kobj_type::release__must_initseries through the driver-core tree with subsystem ACKs, and this is one of the last two patches awaiting an Acked-by. Does this look okay to go via driver-core?
Sorry, this got buried somehow. The patch looks fine to me. Let me ack it.
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Re: [PATCH v3 3/9] sh: sq: Add missing kobject release callback to ktype_percpu_entry
In reply to Ian RogersHi Ian,
Quoted 21 lines · Ian Rogers
In
sq_dev_add(), sq_kobject[cpu] is dynamically allocated withkzalloc_obj()and initialized withktype_percpu_entry. Whensq_dev_remove()callskobject_put(kobj), the kobject is never freed becausektype_percpu_entrylacks a .release callback.Provide a
sq_kobj_release()callback that calls kfree(kobj).Fixes d7c30c682a27 ("sh: Store Queue API rework.")Signed-off-by Ian Rogers <[email protected]>--- arch/sh/kernel/cpu/sh4/sq.c | 6 ++++++ 1 file changed, 6 insertions(+)arch/sh/kernel/cpu/sh4/sq.c +0
-0@@ -331,7 +331,13 @@ static const struct sysfs_ops sq_sysfs_ops = { .store = sq_sysfs_store, };
arch/sh/kernel/cpu/sh4/sq.c static const struct sysfs_ops sq_sysfs_ops = { · line 343
Quoted 10 lines
arch/sh/kernel/cpu/sh4/sq.c +6
-0+static void sq_kobj_release (struct kobject *kobj) +{ +kfree (kobj); +} +static struct kobj_type ktype_percpu_entry = { + .release = sq_kobj_release, .sysfs_ops = &sq_sysfs_ops, .default_groups = sq_sysfs_groups, };
Looks good to me, thanks!
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer `. `' Physicist `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Re: [PATCH v3 2/9] powerpc/secvar: Add missing kobject release callback to secvar_ktype
In reply to Ian RogersQuoted 11 lines · Ian Rogers
In
add_var(), a struct kobject is dynamically allocated withkzalloc_obj()and initialized withsecvar_ktype. Ifkobject_add()orsysfs_create_file()fails,kobject_put(kobj)is called to clean up. However,secvar_ktypedoes not define a .release callback, which results in a memory leak of kobj (and apr_debugwarning inkobject_cleanup()whenCONFIG_DEBUG_KOBJECT_RELEASEis enabled).Provide a
secvar_release()callback that calls kfree(kobj).Fixes bd5d9c743d38 ("powerpc: expose secure variables to userspace via sysfs")Signed-off-by Ian Rogers <[email protected]>
LGTM,
thank you!
Quoted 22 lines
--- arch/powerpc/kernel/secvar-sysfs.c | 6 ++++++ 1 file changed, 6 insertions(+)arch/powerpc/kernel/secvar-sysfs.c +6
-0@@ -126,7 +126,13 @@ static const struct attribute_group secvar_attr_group = { };__ATTRIBUTE_GROUPS (secvar_attr); +static void secvar_release (struct kobject *kobj) +{ +kfree (kobj); +} +static const struct kobj_type secvar_ktype = { + .release = secvar_release, .sysfs_ops = &kobj_sysfs_ops, .default_groups = secvar_attr_groups, };
Re: [PATCH v3 2/9] powerpc/secvar: Add missing kobject release callback to secvar_ktype
In reply to Ian RogersQuoted 12 lines · Ian Rogers
Quoted 11 lines · Ian Rogers
In
add_var(), a struct kobject is dynamically allocated withkzalloc_obj()and initialized withsecvar_ktype. Ifkobject_add()orsysfs_create_file()fails,kobject_put(kobj)is called to clean up. However,secvar_ktypedoes not define a .release callback, which results in a memory leak of kobj (and apr_debugwarning inkobject_cleanup()whenCONFIG_DEBUG_KOBJECT_RELEASEis enabled).Provide a
secvar_release()callback that calls kfree(kobj).Fixes bd5d9c743d38 ("powerpc: expose secure variables to userspace via sysfs")Signed-off-by Ian Rogers <[email protected]>
Quoted 7 lines
Gentle ping on this patch (moving PowerPC maintainers to To: in case this got buried in Cc:).
Danilo offered to take the full 9-patch
kobj_type::release__must_initseries through the driver-core tree with subsystem ACKs, and this is one of the last two patches awaiting an Acked-by. Does this look okay to go via driver-core?
Sure Ian
Quoted 29 lines
Thanks,
IanQuoted 25 lines
--- arch/powerpc/kernel/secvar-sysfs.c | 6 ++++++ 1 file changed, 6 insertions(+)arch/powerpc/kernel/secvar-sysfs.c +6
-1@@ -126,7 +126,13 @@ static const struct attribute_group secvar_attr_group = { };__ATTRIBUTE_GROUPS (secvar_attr); +static void secvar_release (struct kobject *kobj) +{ +kfree (kobj); +} +static const struct kobj_type secvar_ktype = { + .release = secvar_release, .sysfs_ops = &kobj_sysfs_ops, .default_groups = secvar_attr_groups, }; --2.56.0.455.g6c5a503b38-goog
Quoted 104 lines · Ian Rogers
Clang supports the '
require_explicit_initialization' attribute on struct fields to enforce that the field is explicitly initialized when an aggregate object is constructed, emitting -Wuninitialized-explicit-init (enabled by default) if the field is omitted.Following discussion at the Linux Plumbers Conference [1], patch 1 adds the attribute to
include/linux/compiler_attributes.has__must_init. In v1 it was called__require_explicit_initialization. Kees picked up that patch with a firstseq_fileuser [2], and in that thread Greg suggested the shorter__must_initspelling, which Kees and Miguel agreed to. As the attribute did not land in the v7.4 merge window, Kees asked that this series carry the renamed attribute.As
Documentation/core-api/kobject.rstnotes:
"One important point cannot be overstated: every kobject must have arelease()method, and the kobject must persist (in a consistent state) until that method is called. If these constraints are not met, the code is flawed."Annotating struct
kobj_type::releasecaught structkobj_typedefinitions across the tree that omitted .release:
- Patches 2-8 fix structkobj_typedefinitions where dynamically allocated kobjects, ksets, or enclosing structures were either leaked onkobject_put(), freed prematurely before kobject release, or missing proper static initializers.
- Patch 9 annotates structkobj_type::releasewith__must_initand explicitly sets .release = NULL (with explanatory comments prefixed with "Pre-existing:") on the remaining legacy structkobj_typedefinitions whose kobjects are static, per-CPU, permanent firmware structures, or embedded in devm- or parent-managed allocations.Danilo Krummrich offered to route the series as a whole through the driver-core tree [3]. Subsystem maintainer Acked-by tags are still needed (and would be much appreciated!) for the following three patches:
- Patch 2: powerpc/secvar: Add missing kobject release callback tosecvar_ktype
- Patch 3: sh: sq: Add missing kobject release callback toktype_percpu_entry
- Patch 6: xen/sys-hypervisor: Add release callback tohyp_sysfs_kobj_typeNote on tool use: An LLM coding assistant was used to help audit the compiler diagnostics across the tree, draft the fixes and changelog descriptions, and verify builds and review feedback.
Changes in v3:
- Rebased on v7.4-rc1.
- Note in cover letter that patches 2 (powerpc/secvar), 3 (sh: sq), and 6 (xen/sys-hypervisor) are still awaiting subsystem Acked-by tags for merging through the driver-core tree, and CC those maintainers on the cover letter.
- Patch 1: Add Reviewed-by from Kees Cook; clarify that LLVM issue #232483 affects Clang versions prior to its upstream fix (pointed out by Nathan Chancellor).
- Patch 4 (cpufreq): Drop obsolete reference tocpufreq_governor_dbsin the commit message per Zhongqiu Han; add Reviewed-by from Zhongqiu Han and Acked-by from Rafael J. Wysocki and Viresh Kumar.
- Patch 5 (dlm): Add Acked-by from Alexander Aring.
- Patch 8 (drm/amdkfd): Add Reviewed-by from Felix Kuehling.
- Patch 9 (kobject): Fix omapfbmanager-sysfs.candoverlay-sysfs.ccomments to describe managers[] and overlays[] as dynamically allocated rather than static and note theCONFIG_DEBUG_KOBJECT_RELEASEhazard, fix a struct-vs-member wording nit inusnic_ib_sysfs.c, and generalize the commit message note onCONFIG_DEBUG_KOBJECT_RELEASE(reported by Sashiko).Changes in v2:
- Rebased on v7.3-16928-g83f32c773255 (v7.4 merge window).
- Patch 1: Rename__require_explicit_initializationto__must_initper Greg Kroah-Hartman; document the Clang >= 20 requirement per Miguel Ojeda; note the Clang gap for file-scope objects without an initializer reported by Kees Cook; add tags from v1 and from Kees's posting.
- Move LLM assistance attribution from Assisted-by tags to this cover letter per commit1e035297ffda("docs: remove Assisted-by references").
- Patch 4 (cpufreq): Use "cpufreq: governor:" prefix, drop Fixes tag, fix typo, and remove the redundant runtime assignment incpufreq_dbs_governor_init()per Zhongqiu Han.
- Dropped v1 patch 5 (ACPI: CPPC), already fixed upstream by commit27954e29d7de("ACPI: CPPC: Release CPC descriptors through kobject").
- Patch 5 (dlm): Callkobject_del()beforedlm_recoverd_stop()inrelease_lockspace()and thenew_lockspace()error path, and wait on a newls_kobj_donecompletion before freeing the lockspace or dropping the module reference, avoiding races with delayed kobject release.
- Dropped v1 patch 8 (s390/sclp_mem) per Sumanth Korikkar: the/sys/firmware/memory/memoryXkobjects are permanent, sosclp_mem.cis folded into patch 9 with .release = NULL.
- Patch 7 (ubifs): Add Tested-by and Reviewed-by from Zhihao Cheng.
- Patch 8 (drm/amdkfd): Checkq->kobj.state_in_sysfsbeforekobject_del()inkfd_procfs_del_queue().
- Patch 9 (kobject): Coversclp_mem.cand the newamdgpu_ualink.cualink_xcp_info_ktype, fix theoverlay-sysfs.ccomment, and prefix legacy .release = NULL comments with "Pre-existing:".
- Patch 9 (kobject): The ioat,kunpeng_hccsand omapfb display comments now say that the existing teardown can use-after-free underCONFIG_DEBUG_KOBJECT_RELEASE(reported by Sashiko). Fixing those drivers is left to follow-up patches.v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
[1] https://lpc.events/event/20/contributions/2392/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
Quoted 10 lines
Ian Rogers (9):
Compiler Attributes: Add__must_initmacro
powerpc/secvar: Add missing kobject release callback tosecvar_ktype
sh: sq: Add missing kobject release callback toktype_percpu_entry
cpufreq: governor: Initializekobj_typerelease callback statically
dlm: Freedlm_lsin kobject release callback xen/sys-hypervisor: Add release callback tohyp_sysfs_kobj_type
ubifs: sysfs: Usekset_create_and_add()forubifs_ksetdrm/amdkfd: Free queue inprocfs_queue_typekobject release callback
kobject: Require explicit initialization of structkobj_type::release
Hi Danilo,
Just a quick heads-up that all three remaining subsystem ACKs have now arrived on the v3 thread:
- 2/9 (powerpc/secvar): Acked-by Madhavan Srinivasan, Reviewed-by
Srish Srinivasan
- 3/9 (sh: sq): Acked-by John Paul Adrian Glaubitz
- 6/9 (xen/sys-hypervisor): Reviewed-by Juergen Gross
v3 still applies cleanly to driver-core-next (and b4 picks up all the tags). Sashiko did flag more accurate Fixes: SHAs on 5/9 (8a4cf500f1dd) and 7/9 (2e3cbf425804) — happy to send a quick v4 with those and the new tags folded in if you prefer, otherwise v3 is ready as-is.
Thanks,
Ian
Quoted 41 lines
Documentation/conf.py | 1 + arch/arm64/kernel/cpuinfo.c | 5 ++++ arch/powerpc/kernel/secvar-sysfs.c | 6 +++++ arch/sh/kernel/cpu/sh4/sq.c | 6 +++++ drivers/acpi/sysfs.c | 2 ++ drivers/cpufreq/cpufreq_conservative.c | 5 +++- drivers/cpufreq/cpufreq_governor.c | 4 +-- drivers/cpufreq/cpufreq_governor.h | 1 + drivers/cpufreq/cpufreq_ondemand.c | 5 +++- drivers/dma/ioat/sysfs.c | 7 +++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 5 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 10 +++++++ drivers/gpu/drm/amd/amdkfd/kfd_process.c | 12 ++++++--- drivers/gpu/drm/amd/amdkfd/kfd_queue.c | 5 +++- drivers/infiniband/hw/hfi1/sysfs.c | 5 ++++ drivers/infiniband/hw/usnic/usnic_ib_sysfs.c | 5 ++++ drivers/parisc/pdc_stable.c | 5 ++++ drivers/power/supply/ab8500_fg.c | 5 ++++ drivers/s390/char/sclp_mem.c | 2 ++ drivers/soc/hisilicon/kunpeng_hccs.c | 21 +++++++++++++++ .../fbdev/omap2/omapfb/dss/display-sysfs.c | 7 +++++ .../fbdev/omap2/omapfb/dss/manager-sysfs.c | 8 ++++++ .../fbdev/omap2/omapfb/dss/overlay-sysfs.c | 8 ++++++ drivers/xen/sys-hypervisor.c | 6 +++++ fs/dlm/dlm_internal.h | 1 + fs/dlm/lockspace.c | 26 ++++++++++++++----- fs/erofs/sysfs.c | 10 +++++++ fs/f2fs/sysfs.c | 15 +++++++++++ fs/ocfs2/cluster/masklog.c | 5 ++++ fs/ubifs/sysfs.c | 24 +++++------------ include/linux/compiler_attributes.h | 12 +++++++++ include/linux/kobject.h | 2 +- scripts/checkpatch.pl | 1 + tools/lib/python/kdoc/xforms_lists.py | 1 + 34 files changed, 211 insertions(+), 32 deletions(-)base-commit:
6628e7d4c6b25c8d18f1345e3a20d21829aae7e4--
2.56.0.455.g6c5a503b38-goog
Danilo Krummrich
maintainerQuoted 9 lines · Ian Rogers
Hi Danilo,
Just a quick heads-up that all three remaining subsystem ACKs have now arrived on the v3 thread:
- 2/9 (powerpc/secvar): Acked-by Madhavan Srinivasan, Reviewed-by
Srish Srinivasan
- 3/9 (sh: sq): Acked-by John Paul Adrian Glaubitz
- 6/9 (xen/sys-hypervisor): Reviewed-by Juergen Gross
Quoted 5 lines
v3 still applies cleanly to driver-core-next (and b4 picks up all the tags). Sashiko did flag more accurate Fixes: SHAs on 5/9 (
8a4cf500f1dd) and 7/9 (2e3cbf425804) — happy to send a quick v4 with those and the new tags folded in if you prefer, otherwise v3 is ready as-is.
No need to respin for tags, but I think it would be good to respin for the last patch, I will leave a comment there.
Thanks,
Danilo
Danilo Krummrich
maintainerRe: [PATCH v3 9/9] kobject: Require explicit initialization of struct kobj_type::release
In reply to Ian Rogersarch/arm64/kernel/cpuinfo.c const struct seq_operations cpuinfo_op = { · line 301
Quoted 5 lines · Ian Rogers
static const struct
kobj_typecpuregs_kobj_type= {arch/arm64/kernel/cpuinfo.c +4
-0+/* +* Pre-existing: info->kobj is embedded in per-CPU cpu_data; +* cpuid_cpu_offline() only calls kobject_del(). +*/
All of these comments carry a “Pre-existing:” prefix, but that doesn’t distinguish cases with broken lifetime management from those where the storage remains valid despite the API misuse.
For example:
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c static const struct sysfs_ops xcp_cfg_res_sysfs_ops = { · line 804
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +5
-0@@ -797,6 +797,11 @@ static const struct sysfs_ops xcp_cfg_res_sysfs_ops = { };static const struct kobj_type xcp_cfg_res_sysfs_ktype = { +/* +* Pre-existing: xcp_res is embedded in struct amdgpu_xcp_cfg +* rather than freed individually by kobject_put(). +*/ + .release =NULL ,
Being embedded in another structure doesn't explain what guarantees that the enclosing allocation outlives the kobject’s final cleanup.
Could you please drop the “Pre-existing:” prefix and make that distinction explicit? For broken cases, describe the lifetime problem and mark it as needing a follow-up fix. For cases where the lifetime is safe, explain what guarantees that safety, while acknowledging that omitting release() still violates the documented API contract.
Also, do you plan to follow up on those cases?
Thanks,
Danilo
Re: [PATCH v3 9/9] kobject: Require explicit initialization of struct kobj_type::release
Quoted 31 lines · Danilo Krummrich
arch/arm64/kernel/cpuinfo.c const struct seq_operations cpuinfo_op = { · line 301
Quoted 5 lines · Ian Rogers
static const struct
kobj_typecpuregs_kobj_type= {arch/arm64/kernel/cpuinfo.c +4
-0+/* +* Pre-existing: info->kobj is embedded in per-CPU cpu_data; +* cpuid_cpu_offline() only calls kobject_del(). +*/ All of these comments carry a “Pre-existing:” prefix, but that doesn’t distinguish cases with broken lifetime management from those where the storage remains valid despite the API misuse.
For example:
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c static const struct sysfs_ops xcp_cfg_res_sysfs_ops = { · line 804
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +5
-0@@ -797,6 +797,11 @@ static const struct sysfs_ops xcp_cfg_res_sysfs_ops = { };static const struct kobj_type xcp_cfg_res_sysfs_ktype = { +/* +* Pre-existing: xcp_res is embedded in struct amdgpu_xcp_cfg +* rather than freed individually by kobject_put(). +*/ + .release =NULL ,Being embedded in another structure doesn't explain what guarantees that the enclosing allocation outlives the kobject’s final cleanup.
Quoted 7 lines
Could you please drop the “Pre-existing:” prefix and make that distinction explicit? For broken cases, describe the lifetime problem and mark it as needing a follow-up fix. For cases where the lifetime is safe, explain what guarantees that safety, while acknowledging that omitting
release()still violates the documented API contract.Also, do you plan to follow up on those cases?
Makes complete sense, thanks Danilo!
Auditing all 17 files in patch 9 with that distinction in mind:
- Only 3 built-in sites (arm64 cpuinfo, ACPI hotplug profiles, and s390 sclp_mem) have backing storage that genuinely remains valid for the lifetime of the kernel.
- The other 14 files either free/zero an enclosing dynamic or devm allocation without waiting for final kobject cleanup, or are tristate modules that unregister static kobjects/ksets on module_exit and can unmap module memory before delayed cleanup finishes.
I've dropped the "Pre-existing:" prefix, documented the specific guarantee or FIXME lifetime hazard at each site in v4, and yes, I plan to send follow-up fixes to the respective subsystems once __must_init is in place.
Thanks,
Ian
Quoted 3 lines
Thanks,
Danilo