All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>, "Kees Cook" <kees@kernel.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	"Danilo Krummrich" <dakr@kernel.org>
Cc: "Nathan Chancellor" <nathan@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Miguel Ojeda" <miguel.ojeda.sandonis@gmail.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Zhihao Cheng" <chengzhihao1@huawei.com>,
	"Zhongqiu Han" <zhongqiu.han@oss.qualcomm.com>,
	"Sumanth Korikkar" <sumanthk@linux.ibm.com>,
	"Bill Wendling" <morbo@google.com>,
	"Justin Stitt" <justinstitt@google.com>,
	linux-s390@vger.kernel.org, linux-mtd@lists.infradead.org,
	dri-devel@lists.freedesktop.org,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Will Deacon" <will@kernel.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Len Brown" <lenb@kernel.org>, "Vinod Koul" <vkoul@kernel.org>,
	"Frank Li" <Frank.Li@kernel.org>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Dennis Dalessandro" <dennis.dalessandro@cornelisnetworks.com>,
	"Jason Gunthorpe" <jgg@ziepe.ca>,
	"Leon Romanovsky" <leon@kernel.org>,
	"Nelson Escobar" <neescoba@cisco.com>,
	"Satish Kharat" <satishkh@cisco.com>,
	"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	"Helge Deller" <deller@gmx.de>,
	"Linus Walleij" <linusw@kernel.org>,
	"Sebastian Reichel" <sre@kernel.org>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Sven Schnelle" <svens@linux.ibm.com>,
	"Huisong Li" <lihuisong@huawei.com>,
	"Gao Xiang" <xiang@kernel.org>, "Chao Yu" <chao@kernel.org>,
	"Yue Hu" <zbestahu@gmail.com>, "Jingbo Xu" <jefflexu@163.com>,
	"Sandeep Dhavale" <dhavale@google.com>,
	"Hongbo Li" <hongbohbli@tencent.com>,
	"Chunhai Guo" <guochunhai@vivo.com>,
	"Jaegeuk Kim" <jaegeuk@kernel.org>,
	"Mark Fasheh" <mark@fasheh.com>,
	"Joel Becker" <jlbec@evilplan.org>,
	"Joseph Qi" <joseph.qi@linux.alibaba.com>,
	"Heming Zhao" <heming.zhao@suse.com>,
	"Johan Hovold" <johan@kernel.org>,
	dmaengine@vger.kernel.org, linux-rdma@vger.kernel.org
Subject: Re: [PATCH v2 9/9] kobject: Require explicit initialization of struct kobj_type::release
Date: Tue, 27 Oct 2026 22:56:16 +0000	[thread overview]
Message-ID: <sashiko-outbox-187180@kernel.org> (raw)
In-Reply-To: <20261027223847.652884-10-irogers@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] fbdev: omapdss: inaccurate kobj_type comments for managers and overlays
- [Low] kobject: inaccurate kobj_type comments on static lifetime and delayed release
--

commit 2811dd0d4494f584b7b3fad73d8e6b9f2f067c96
Author: Ian Rogers <irogers@google.com>

kobject: Require explicit initialization of struct kobj_type::release

This commit annotates struct kobj_type::release with __must_init so the
compiler diagnoses any struct kobj_type initializer that omits .release. For
remaining legacy struct kobj_type definitions that do not free their kobject
via kobject_put(), it explicitly initializes .release = NULL with comments
documenting the kobject lifetime and CONFIG_DEBUG_KOBJECT_RELEASE behavior.

Link: https://lpc.events/event/20/contributions/2392/

>     kobject: Require explicit initialization of struct kobj_type::release
>     
>     Documentation/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, permanent firmware structures, or embedded inside a
>     devm- or parent-managed structure rather than freed by kobject_put(),
>     explicitly initialize .release = NULL with a comment documenting why no
>     release callback is provided.
>     
>     Where the existing teardown is not safe with CONFIG_DEBUG_KOBJECT_RELEASE,
>     because the kobject's memory can be freed or cleared while the delayed
>     kobject cleanup is still pending (ioat, kunpeng_hccs and omapfb display),
>     the comment says so. Fixing those is left to follow-up patches; this
>     change does not alter their behavior.
>     
>     Link: https://lpc.events/event/20/contributions/2392/
>     Signed-off-by: Ian Rogers <irogers@google.com>

[Severity: Low]
The commit message notes that where existing teardown is not safe with
CONFIG_DEBUG_KOBJECT_RELEASE (listing ioat, kunpeng_hccs, and omapfb
display), the comment says so.

Are there additional kobj_type definitions touched in this patch where the
backing memory is freed, zeroed, or unmapped while delayed kobject cleanup is
still pending under CONFIG_DEBUG_KOBJECT_RELEASE, such as omapfb manager_ktype
and overlay_ktype, amdgpu ualink_xcp_info_ktype and xcp_sysfs_ktype, hfi1
sde_ktype, usnic usnic_ib_qpn_type, ab8500_fg_ktype (on the
kobject_init_and_add() error path in ab8500_fg_sysfs_init() before devm frees
di), and the static kobjects/ksets in loadable modules (erofs, f2fs, ocfs2,
and pdc_stable on module unload)?

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> index 17888cf544472..c2cccd924b03c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> @@ -885,6 +885,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
>  };
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
> index ab14079d1c422..0847134a13917 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c

[ ... ]

> @@ -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,
>  };

[Severity: Low]
Should the comments on ualink_xcp_info_ktype and xcp_sysfs_ktype also note the
CONFIG_DEBUG_KOBJECT_RELEASE use-after-free hazard?

During teardown, amdgpu_device_fini_hw() calls amdgpu_ualink_sysfs_fini() and
amdgpu_xcp_sysfs_fini(), which call kobject_put(&xcp->ualink.kobj) and
kobject_put(&xcp->kobj), and then amdgpu_device_fini_sw() frees adev->xcp_mgr
while delayed kobject cleanup may still be pending.

> diff --git a/drivers/infiniband/hw/hfi1/sysfs.c b/drivers/infiniband/hw/hfi1/sysfs.c
> index 372cfd13dc616..5a1aca06b542b 100644
> --- a/drivers/infiniband/hw/hfi1/sysfs.c
> +++ b/drivers/infiniband/hw/hfi1/sysfs.c
> @@ -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,
>  };

[Severity: Low]
Does sde_ktype also have the same CONFIG_DEBUG_KOBJECT_RELEASE use-after-free
issue worth noting in this comment?

In the device removal path, hfi1_verbs_unregister_sysfs() calls
kobject_put(&dd->per_sdma[i].kobj) right before remove_one() ->
hfi1_free_devdata() -> sdma_clean() calls kfree(dd->per_sdma).

> diff --git a/drivers/infiniband/hw/usnic/usnic_ib_sysfs.c b/drivers/infiniband/hw/usnic/usnic_ib_sysfs.c
> index fdb63a8fb9974..df0e48070c2ee 100644
> --- a/drivers/infiniband/hw/usnic/usnic_ib_sysfs.c
> +++ b/drivers/infiniband/hw/usnic/usnic_ib_sysfs.c
> @@ -245,6 +245,8 @@ static struct attribute *usnic_ib_qpn_default_attrs[] = {
>  ATTRIBUTE_GROUPS(usnic_ib_qpn_default);
>  
>  static struct kobj_type usnic_ib_qpn_type = {
> +	/* Pre-existing: usnic_ib_qp_grp is embedded in RDMA core-managed struct usnic_ib_qp_grp. */
> +	.release = NULL,
>  	.sysfs_ops = &usnic_ib_qpn_sysfs_ops,
>  	.default_groups = usnic_ib_qpn_default_groups,
>  };

[Severity: Low]
Should this comment on usnic_ib_qpn_type also mention
CONFIG_DEBUG_KOBJECT_RELEASE?

When destroying a QP, ib_destroy_qp_user() calls usnic_ib_destroy_qp() ->
usnic_ib_sysfs_qpn_remove(), which calls kobject_put(&qp_grp->kobj)
immediately before the RDMA core frees the struct usnic_ib_qp_grp allocation.

> diff --git a/drivers/video/fbdev/omap2/omapfb/dss/manager-sysfs.c b/drivers/video/fbdev/omap2/omapfb/dss/manager-sysfs.c
> index 1b644be5fe2ed..40ec750f43155 100644
> --- a/drivers/video/fbdev/omap2/omapfb/dss/manager-sysfs.c
> +++ b/drivers/video/fbdev/omap2/omapfb/dss/manager-sysfs.c
> @@ -496,6 +496,11 @@ static const struct sysfs_ops manager_sysfs_ops = {
>  };
>  
>  static struct kobj_type manager_ktype = {
> +	/*
> +	 * Pre-existing: mgr->kobj is embedded in static managers[] and
> +	 * zeroed in dss_manager_kobj_uninit().
> +	 */
> +	.release = NULL,
>  	.sysfs_ops = &manager_sysfs_ops,
>  	.default_groups = manager_sysfs_groups,
>  };

[Severity: Low]
Is managers[] actually a static array here, and does this teardown also
corrupt pending delayed cleanup under CONFIG_DEBUG_KOBJECT_RELEASE?

In drivers/video/fbdev/omap2/omapfb/dss/manager.c, managers is dynamically
allocated on the heap in dss_init_overlay_managers() and freed in
dss_uninit_overlay_managers():

static struct omap_overlay_manager *managers;

int dss_init_overlay_managers(void)
{
	int i;

	num_managers = dss_feat_get_num_mgrs();

	managers = kzalloc_objs(struct omap_overlay_manager, num_managers);
	...
}

In addition, dss_manager_kobj_uninit() calls
memset(&mgr->kobj, 0, sizeof(mgr->kobj)) right after kobject_put(&mgr->kobj)
(and dss_uninit_overlay_managers() then calls kfree(managers)), which clobbers
and frees the pending delayed kobject cleanup under
CONFIG_DEBUG_KOBJECT_RELEASE just like display_uninit_sysfs() in
display-sysfs.c.

> diff --git a/drivers/video/fbdev/omap2/omapfb/dss/overlay-sysfs.c b/drivers/video/fbdev/omap2/omapfb/dss/overlay-sysfs.c
> index 1da4fb1c77b4a..4d333031b18d6 100644
> --- a/drivers/video/fbdev/omap2/omapfb/dss/overlay-sysfs.c
> +++ b/drivers/video/fbdev/omap2/omapfb/dss/overlay-sysfs.c
> @@ -429,6 +429,11 @@ static const struct sysfs_ops overlay_sysfs_ops = {
>  };
>  
>  static struct kobj_type overlay_ktype = {
> +	/*
> +	 * Pre-existing: ovl->kobj is embedded in static overlays[];
> +	 * dss_overlay_kobj_uninit() drops the kobject ref.
> +	 */
> +	.release = NULL,
>  	.sysfs_ops = &overlay_sysfs_ops,
>  	.default_groups = overlay_sysfs_groups,
>  };

[Severity: Low]
Similarly, is overlays[] heap-allocated rather than static, with a
use-after-free under CONFIG_DEBUG_KOBJECT_RELEASE?

In drivers/video/fbdev/omap2/omapfb/dss/overlay.c, overlays is allocated via
kzalloc_objs(struct omap_overlay, num_overlays) in dss_init_overlays(), and
dss_uninit_overlays() frees it immediately after dss_overlay_kobj_uninit()
calls kobject_put(&ovl->kobj):

void dss_uninit_overlays(struct platform_device *pdev)
{
	int i;

	for (i = 0; i < num_overlays; ++i) {
		struct omap_overlay *ovl = &overlays[i];
		dss_overlay_kobj_uninit(ovl);
	}

	kfree(overlays);
	overlays = NULL;
	num_overlays = 0;
}

Should the comments on manager_ktype and overlay_ktype describe managers and
overlays as dynamically allocated arrays and note the
CONFIG_DEBUG_KOBJECT_RELEASE hazard as well?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261027223847.652884-1-irogers@google.com?part=9

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>, "Kees Cook" <kees@kernel.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	"Danilo Krummrich" <dakr@kernel.org>
Cc: "Nathan Chancellor" <nathan@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Miguel Ojeda" <miguel.ojeda.sandonis@gmail.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Zhihao Cheng" <chengzhihao1@huawei.com>,
	"Zhongqiu Han" <zhongqiu.han@oss.qualcomm.com>,
	"Sumanth Korikkar" <sumanthk@linux.ibm.com>,
	"Bill Wendling" <morbo@google.com>,
	"Justin Stitt" <justinstitt@google.com>,
	linux-s390@vger.kernel.org, linux-mtd@lists.infradead.org,
	dri-devel@lists.freedesktop.org,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Will Deacon" <will@kernel.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Len Brown" <lenb@kernel.org>, "Vinod Koul" <vkoul@kernel.org>,
	"Frank Li" <Frank.Li@kernel.org>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Dennis Dalessandro" <dennis.dalessandro@cornelisnetworks.com>,
	"Jason Gunthorpe" <jgg@ziepe.ca>,
	"Leon Romanovsky" <leon@kernel.org>,
	"Nelson Escobar" <neescoba@cisco.com>,
	"Satish Kharat" <satishkh@cisco.com>,
	"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	"Helge Deller" <deller@gmx.de>,
	"Linus Walleij" <linusw@kernel.org>,
	"Sebastian Reichel" <sre@kernel.org>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Sven Schnelle" <svens@linux.ibm.com>,
	"Huisong Li" <lihuisong@huawei.com>,
	"Gao Xiang" <xiang@kernel.org>, "Chao Yu" <chao@kernel.org>,
	"Yue Hu" <zbestahu@gmail.com>, "Jingbo Xu" <jefflexu@163.com>,
	"Sandeep Dhavale" <dhavale@google.com>,
	"Hongbo Li" <hongbohbli@tencent.com>,
	"Chunhai Guo" <guochunhai@vivo.com>,
	"Jaegeuk Kim" <jaegeuk@kernel.org>,
	"Mark Fasheh" <mark@fasheh.com>,
	"Joel Becker" <jlbec@evilplan.org>,
	"Joseph Qi" <joseph.qi@linux.alibaba.com>,
	"Heming Zhao" <heming.zhao@suse.com>,
	"Johan Hovold" <johan@kernel.org>,
	dmaengine@vger.kernel.org, linux-rdma@vger.kernel.org
Subject: Re: [PATCH v2 9/9] kobject: Require explicit initialization of struct kobj_type::release
Date: Tue, 27 Oct 2026 22:56:16 +0000	[thread overview]
Message-ID: <sashiko-outbox-187180@kernel.org> (raw)
In-Reply-To: <20261027223847.652884-10-irogers@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] fbdev: omapdss: inaccurate kobj_type comments for managers and overlays
- [Low] kobject: inaccurate kobj_type comments on static lifetime and delayed release
--

commit 2811dd0d4494f584b7b3fad73d8e6b9f2f067c96
Author: Ian Rogers <irogers@google.com>

kobject: Require explicit initialization of struct kobj_type::release

This commit annotates struct kobj_type::release with __must_init so the
compiler diagnoses any struct kobj_type initializer that omits .release. For
remaining legacy struct kobj_type definitions that do not free their kobject
via kobject_put(), it explicitly initializes .release = NULL with comments
documenting the kobject lifetime and CONFIG_DEBUG_KOBJECT_RELEASE behavior.

Link: https://lpc.events/event/20/contributions/2392/

>     kobject: Require explicit initialization of struct kobj_type::release
>     
>     Documentation/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, permanent firmware structures, or embedded inside a
>     devm- or parent-managed structure rather than freed by kobject_put(),
>     explicitly initialize .release = NULL with a comment documenting why no
>     release callback is provided.
>     
>     Where the existing teardown is not safe with CONFIG_DEBUG_KOBJECT_RELEASE,
>     because the kobject's memory can be freed or cleared while the delayed
>     kobject cleanup is still pending (ioat, kunpeng_hccs and omapfb display),
>     the comment says so. Fixing those is left to follow-up patches; this
>     change does not alter their behavior.
>     
>     Link: https://lpc.events/event/20/contributions/2392/
>     Signed-off-by: Ian Rogers <irogers@google.com>

[Severity: Low]
The commit message notes that where existing teardown is not safe with
CONFIG_DEBUG_KOBJECT_RELEASE (listing ioat, kunpeng_hccs, and omapfb
display), the comment says so.

Are there additional kobj_type definitions touched in this patch where the
backing memory is freed, zeroed, or unmapped while delayed kobject cleanup is
still pending under CONFIG_DEBUG_KOBJECT_RELEASE, such as omapfb manager_ktype
and overlay_ktype, amdgpu ualink_xcp_info_ktype and xcp_sysfs_ktype, hfi1
sde_ktype, usnic usnic_ib_qpn_type, ab8500_fg_ktype (on the
kobject_init_and_add() error path in ab8500_fg_sysfs_init() before devm frees
di), and the static kobjects/ksets in loadable modules (erofs, f2fs, ocfs2,
and pdc_stable on module unload)?

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> index 17888cf544472..c2cccd924b03c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> @@ -885,6 +885,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
>  };
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
> index ab14079d1c422..0847134a13917 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c

[ ... ]

> @@ -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,
>  };

[Severity: Low]
Should the comments on ualink_xcp_info_ktype and xcp_sysfs_ktype also note the
CONFIG_DEBUG_KOBJECT_RELEASE use-after-free hazard?

During teardown, amdgpu_device_fini_hw() calls amdgpu_ualink_sysfs_fini() and
amdgpu_xcp_sysfs_fini(), which call kobject_put(&xcp->ualink.kobj) and
kobject_put(&xcp->kobj), and then amdgpu_device_fini_sw() frees adev->xcp_mgr
while delayed kobject cleanup may still be pending.

> diff --git a/drivers/infiniband/hw/hfi1/sysfs.c b/drivers/infiniband/hw/hfi1/sysfs.c
> index 372cfd13dc616..5a1aca06b542b 100644
> --- a/drivers/infiniband/hw/hfi1/sysfs.c
> +++ b/drivers/infiniband/hw/hfi1/sysfs.c
> @@ -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,
>  };

[Severity: Low]
Does sde_ktype also have the same CONFIG_DEBUG_KOBJECT_RELEASE use-after-free
issue worth noting in this comment?

In the device removal path, hfi1_verbs_unregister_sysfs() calls
kobject_put(&dd->per_sdma[i].kobj) right before remove_one() ->
hfi1_free_devdata() -> sdma_clean() calls kfree(dd->per_sdma).

> diff --git a/drivers/infiniband/hw/usnic/usnic_ib_sysfs.c b/drivers/infiniband/hw/usnic/usnic_ib_sysfs.c
> index fdb63a8fb9974..df0e48070c2ee 100644
> --- a/drivers/infiniband/hw/usnic/usnic_ib_sysfs.c
> +++ b/drivers/infiniband/hw/usnic/usnic_ib_sysfs.c
> @@ -245,6 +245,8 @@ static struct attribute *usnic_ib_qpn_default_attrs[] = {
>  ATTRIBUTE_GROUPS(usnic_ib_qpn_default);
>  
>  static struct kobj_type usnic_ib_qpn_type = {
> +	/* Pre-existing: usnic_ib_qp_grp is embedded in RDMA core-managed struct usnic_ib_qp_grp. */
> +	.release = NULL,
>  	.sysfs_ops = &usnic_ib_qpn_sysfs_ops,
>  	.default_groups = usnic_ib_qpn_default_groups,
>  };

[Severity: Low]
Should this comment on usnic_ib_qpn_type also mention
CONFIG_DEBUG_KOBJECT_RELEASE?

When destroying a QP, ib_destroy_qp_user() calls usnic_ib_destroy_qp() ->
usnic_ib_sysfs_qpn_remove(), which calls kobject_put(&qp_grp->kobj)
immediately before the RDMA core frees the struct usnic_ib_qp_grp allocation.

> diff --git a/drivers/video/fbdev/omap2/omapfb/dss/manager-sysfs.c b/drivers/video/fbdev/omap2/omapfb/dss/manager-sysfs.c
> index 1b644be5fe2ed..40ec750f43155 100644
> --- a/drivers/video/fbdev/omap2/omapfb/dss/manager-sysfs.c
> +++ b/drivers/video/fbdev/omap2/omapfb/dss/manager-sysfs.c
> @@ -496,6 +496,11 @@ static const struct sysfs_ops manager_sysfs_ops = {
>  };
>  
>  static struct kobj_type manager_ktype = {
> +	/*
> +	 * Pre-existing: mgr->kobj is embedded in static managers[] and
> +	 * zeroed in dss_manager_kobj_uninit().
> +	 */
> +	.release = NULL,
>  	.sysfs_ops = &manager_sysfs_ops,
>  	.default_groups = manager_sysfs_groups,
>  };

[Severity: Low]
Is managers[] actually a static array here, and does this teardown also
corrupt pending delayed cleanup under CONFIG_DEBUG_KOBJECT_RELEASE?

In drivers/video/fbdev/omap2/omapfb/dss/manager.c, managers is dynamically
allocated on the heap in dss_init_overlay_managers() and freed in
dss_uninit_overlay_managers():

static struct omap_overlay_manager *managers;

int dss_init_overlay_managers(void)
{
	int i;

	num_managers = dss_feat_get_num_mgrs();

	managers = kzalloc_objs(struct omap_overlay_manager, num_managers);
	...
}

In addition, dss_manager_kobj_uninit() calls
memset(&mgr->kobj, 0, sizeof(mgr->kobj)) right after kobject_put(&mgr->kobj)
(and dss_uninit_overlay_managers() then calls kfree(managers)), which clobbers
and frees the pending delayed kobject cleanup under
CONFIG_DEBUG_KOBJECT_RELEASE just like display_uninit_sysfs() in
display-sysfs.c.

> diff --git a/drivers/video/fbdev/omap2/omapfb/dss/overlay-sysfs.c b/drivers/video/fbdev/omap2/omapfb/dss/overlay-sysfs.c
> index 1da4fb1c77b4a..4d333031b18d6 100644
> --- a/drivers/video/fbdev/omap2/omapfb/dss/overlay-sysfs.c
> +++ b/drivers/video/fbdev/omap2/omapfb/dss/overlay-sysfs.c
> @@ -429,6 +429,11 @@ static const struct sysfs_ops overlay_sysfs_ops = {
>  };
>  
>  static struct kobj_type overlay_ktype = {
> +	/*
> +	 * Pre-existing: ovl->kobj is embedded in static overlays[];
> +	 * dss_overlay_kobj_uninit() drops the kobject ref.
> +	 */
> +	.release = NULL,
>  	.sysfs_ops = &overlay_sysfs_ops,
>  	.default_groups = overlay_sysfs_groups,
>  };

[Severity: Low]
Similarly, is overlays[] heap-allocated rather than static, with a
use-after-free under CONFIG_DEBUG_KOBJECT_RELEASE?

In drivers/video/fbdev/omap2/omapfb/dss/overlay.c, overlays is allocated via
kzalloc_objs(struct omap_overlay, num_overlays) in dss_init_overlays(), and
dss_uninit_overlays() frees it immediately after dss_overlay_kobj_uninit()
calls kobject_put(&ovl->kobj):

void dss_uninit_overlays(struct platform_device *pdev)
{
	int i;

	for (i = 0; i < num_overlays; ++i) {
		struct omap_overlay *ovl = &overlays[i];
		dss_overlay_kobj_uninit(ovl);
	}

	kfree(overlays);
	overlays = NULL;
	num_overlays = 0;
}

Should the comments on manager_ktype and overlay_ktype describe managers and
overlays as dynamically allocated arrays and note the
CONFIG_DEBUG_KOBJECT_RELEASE hazard as well?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261027223847.652884-1-irogers@google.com?part=9

  reply	other threads:[~2026-10-27 22:56 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 22:38 [PATCH v2 0/9] Add __must_init and require explicit kobj_type::release Ian Rogers
2026-10-27 22:38 ` Ian Rogers
2026-10-27 22:38 ` [PATCH v2 1/9] Compiler Attributes: Add __must_init macro Ian Rogers
2026-10-27 22:38   ` Ian Rogers
2026-10-27 22:43   ` sashiko-bot
2026-10-28 18:56   ` Kees Cook
2026-10-28 18:56     ` Kees Cook
2026-10-28 19:02     ` Nathan Chancellor
2026-10-28 19:02       ` Nathan Chancellor
2026-10-27 22:38 ` [PATCH v2 2/9] powerpc/secvar: Add missing kobject release callback to secvar_ktype Ian Rogers
2026-10-27 22:38   ` Ian Rogers
2026-10-27 22:42   ` sashiko-bot
2026-10-27 22:38 ` [PATCH v2 3/9] sh: sq: Add missing kobject release callback to ktype_percpu_entry Ian Rogers
2026-10-27 22:38   ` Ian Rogers
2026-10-27 22:46   ` sashiko-bot
2026-10-27 22:38 ` [PATCH v2 4/9] cpufreq: governor: Initialize kobj_type release callback statically Ian Rogers
2026-10-27 22:38   ` Ian Rogers
2026-10-27 22:43   ` sashiko-bot
2026-10-28  3:36   ` Zhongqiu Han
2026-10-28  3:36     ` Zhongqiu Han
2026-10-28 11:38   ` Rafael J. Wysocki (Intel)
2026-10-28 11:38     ` Rafael J. Wysocki (Intel)
2026-10-28 15:35     ` Ian Rogers
2026-10-28 15:35       ` Ian Rogers
2026-10-28 15:39       ` Rafael J. Wysocki (Intel)
2026-10-28 15:39         ` Rafael J. Wysocki (Intel)
2026-10-27 22:38 ` [PATCH v2 5/9] dlm: Free dlm_ls in kobject release callback Ian Rogers
2026-10-27 22:38   ` Ian Rogers
2026-10-27 22:45   ` sashiko-bot
2026-10-27 22:38 ` [PATCH v2 6/9] xen/sys-hypervisor: Add release callback to hyp_sysfs_kobj_type Ian Rogers
2026-10-27 22:38   ` Ian Rogers
2026-10-27 22:42   ` sashiko-bot
2026-10-27 22:38 ` [PATCH v2 7/9] ubifs: sysfs: Use kset_create_and_add() for ubifs_kset Ian Rogers
2026-10-27 22:38   ` Ian Rogers
2026-10-27 22:42   ` sashiko-bot
2026-10-27 22:38 ` [PATCH v2 8/9] drm/amdkfd: Free queue in procfs_queue_type kobject release callback Ian Rogers
2026-10-27 22:38   ` Ian Rogers
2026-10-27 22:45   ` sashiko-bot
2026-10-27 23:15   ` Felix Kuehling
2026-10-27 23:15     ` Felix Kuehling
2026-10-27 22:38 ` [PATCH v2 9/9] kobject: Require explicit initialization of struct kobj_type::release Ian Rogers
2026-10-27 22:38   ` [f2fs-dev] " Ian Rogers via Linux-f2fs-devel
2026-10-27 22:38   ` Ian Rogers
2026-10-27 22:56   ` sashiko-bot [this message]
2026-10-27 22:56     ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-187180@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=agordeev@linux.ibm.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=catalin.marinas@arm.com \
    --cc=chao@kernel.org \
    --cc=chengzhihao1@huawei.com \
    --cc=christian.koenig@amd.com \
    --cc=dakr@kernel.org \
    --cc=deller@gmx.de \
    --cc=dennis.dalessandro@cornelisnetworks.com \
    --cc=dhavale@google.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gor@linux.ibm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=guochunhai@vivo.com \
    --cc=hca@linux.ibm.com \
    --cc=heming.zhao@suse.com \
    --cc=hongbohbli@tencent.com \
    --cc=irogers@google.com \
    --cc=jaegeuk@kernel.org \
    --cc=jefflexu@163.com \
    --cc=jgg@ziepe.ca \
    --cc=jlbec@evilplan.org \
    --cc=johan@kernel.org \
    --cc=joseph.qi@linux.alibaba.com \
    --cc=justinstitt@google.com \
    --cc=kees@kernel.org \
    --cc=lenb@kernel.org \
    --cc=leon@kernel.org \
    --cc=lihuisong@huawei.com \
    --cc=linusw@kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mark@fasheh.com \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=neescoba@cisco.com \
    --cc=ojeda@kernel.org \
    --cc=rafael@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=satishkh@cisco.com \
    --cc=simona@ffwll.ch \
    --cc=sre@kernel.org \
    --cc=sumanthk@linux.ibm.com \
    --cc=svens@linux.ibm.com \
    --cc=vkoul@kernel.org \
    --cc=will@kernel.org \
    --cc=xiang@kernel.org \
    --cc=zbestahu@gmail.com \
    --cc=zhongqiu.han@oss.qualcomm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.