cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH cgroup/for-6.16-fixes] cgroup: avoid null de-ref in css_rstat_exit()
@ 2025-07-31 19:27 JP Kobryn
  2025-08-01 17:38 ` Shakeel Butt
  0 siblings, 1 reply; 4+ messages in thread
From: JP Kobryn @ 2025-07-31 19:27 UTC (permalink / raw)
  To: tj, shakeel.butt, mkoutny, yosryahmed, hannes, akpm
  Cc: linux-kernel, cgroups, kernel-team

This function may be called asynchronously in scenarios where preceding
calls to css_rstat_init() have not completed. Return early in this case.

Signed-off-by: JP Kobryn <inwardvessel@gmail.com>
Suggested-by: Michal Koutný <mkoutny@suse.com>
Fixes: 5da3bfa029d68 ("cgroup: use separate rstat trees for each subsystem")
Reported-by: syzbot+8d052e8b99e40bc625ed@syzkaller.appspotmail.com
---
 kernel/cgroup/rstat.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
index cbeaa499a96a..408e52d5f7a4 100644
--- a/kernel/cgroup/rstat.c
+++ b/kernel/cgroup/rstat.c
@@ -488,6 +488,9 @@ void css_rstat_exit(struct cgroup_subsys_state *css)
 	if (!css_uses_rstat(css))
 		return;
 
+	if (!css->rstat_cpu)
+		return;
+
 	css_rstat_flush(css);
 
 	/* sanity check */
-- 
2.47.3


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

* Re: [PATCH cgroup/for-6.16-fixes] cgroup: avoid null de-ref in css_rstat_exit()
  2025-07-31 19:27 JP Kobryn
@ 2025-08-01 17:38 ` Shakeel Butt
  0 siblings, 0 replies; 4+ messages in thread
From: Shakeel Butt @ 2025-08-01 17:38 UTC (permalink / raw)
  To: JP Kobryn
  Cc: tj, mkoutny, yosryahmed, hannes, akpm, linux-kernel, cgroups,
	kernel-team

On Thu, Jul 31, 2025 at 12:27:34PM -0700, JP Kobryn wrote:
> This function

Name the function i.e. css_rstat_exit()

> may be called asynchronously in scenarios where preceding
> calls to css_rstat_init() have not completed.

Explain some (or just one) of these scenarios in the commit.

> Return early in this case.
> 
> Signed-off-by: JP Kobryn <inwardvessel@gmail.com>
> Suggested-by: Michal Koutný <mkoutny@suse.com>
> Fixes: 5da3bfa029d68 ("cgroup: use separate rstat trees for each subsystem")
> Reported-by: syzbot+8d052e8b99e40bc625ed@syzkaller.appspotmail.com

With the updated commit message, please include:

Acked-by: Shakeel Butt <shakeel.butt@linux.dev>


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

* [PATCH cgroup/for-6.16-fixes] cgroup: avoid null de-ref in css_rstat_exit()
@ 2025-08-07  0:33 JP Kobryn
  2025-08-09 18:46 ` Tejun Heo
  0 siblings, 1 reply; 4+ messages in thread
From: JP Kobryn @ 2025-08-07  0:33 UTC (permalink / raw)
  To: tj, shakeel.butt, mkoutny, yosryahmed, hannes, akpm
  Cc: linux-kernel, cgroups, kernel-team

css_rstat_exit() may be called asynchronously in scenarios where preceding
calls to css_rstat_init() have not completed. One such example is this
sequence below:

css_create(...)
{
	...
	init_and_link_css(css, ...);

	err = percpu_ref_init(...);
	if (err)
		goto err_free_css;
	err = cgroup_idr_alloc(...);
	if (err)
		goto err_free_css;
	err = css_rstat_init(css, ...);
	if (err)
		goto err_free_css;
	...
err_free_css:
	INIT_RCU_WORK(&css->destroy_rwork, css_free_rwork_fn);
	queue_rcu_work(cgroup_destroy_wq, &css->destroy_rwork);
	return ERR_PTR(err);
}

If any of the three goto jumps are taken, async cleanup will begin and
css_rstat_exit() will be invoked on an uninitialized css->rstat_cpu.

Avoid accessing the unitialized field by returning early in
css_rstat_exit() if this is the case.

Signed-off-by: JP Kobryn <inwardvessel@gmail.com>
Suggested-by: Michal Koutný <mkoutny@suse.com>
Fixes: 5da3bfa029d68 ("cgroup: use separate rstat trees for each subsystem")
Reported-by: syzbot+8d052e8b99e40bc625ed@syzkaller.appspotmail.com
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
---
 kernel/cgroup/rstat.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
index cbeaa499a96a..408e52d5f7a4 100644
--- a/kernel/cgroup/rstat.c
+++ b/kernel/cgroup/rstat.c
@@ -488,6 +488,9 @@ void css_rstat_exit(struct cgroup_subsys_state *css)
 	if (!css_uses_rstat(css))
 		return;
 
+	if (!css->rstat_cpu)
+		return;
+
 	css_rstat_flush(css);
 
 	/* sanity check */
-- 
2.47.3


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

* Re: [PATCH cgroup/for-6.16-fixes] cgroup: avoid null de-ref in css_rstat_exit()
  2025-08-07  0:33 [PATCH cgroup/for-6.16-fixes] cgroup: avoid null de-ref in css_rstat_exit() JP Kobryn
@ 2025-08-09 18:46 ` Tejun Heo
  0 siblings, 0 replies; 4+ messages in thread
From: Tejun Heo @ 2025-08-09 18:46 UTC (permalink / raw)
  To: JP Kobryn
  Cc: shakeel.butt, mkoutny, yosryahmed, hannes, akpm, linux-kernel,
	cgroups, kernel-team

On Wed, Aug 06, 2025 at 05:33:50PM -0700, JP Kobryn wrote:
> css_rstat_exit() may be called asynchronously in scenarios where preceding
> calls to css_rstat_init() have not completed. One such example is this
> sequence below:
> 
> css_create(...)
> {
> 	...
> 	init_and_link_css(css, ...);
> 
> 	err = percpu_ref_init(...);
> 	if (err)
> 		goto err_free_css;
> 	err = cgroup_idr_alloc(...);
> 	if (err)
> 		goto err_free_css;
> 	err = css_rstat_init(css, ...);
> 	if (err)
> 		goto err_free_css;
> 	...
> err_free_css:
> 	INIT_RCU_WORK(&css->destroy_rwork, css_free_rwork_fn);
> 	queue_rcu_work(cgroup_destroy_wq, &css->destroy_rwork);
> 	return ERR_PTR(err);
> }
> 
> If any of the three goto jumps are taken, async cleanup will begin and
> css_rstat_exit() will be invoked on an uninitialized css->rstat_cpu.
> 
> Avoid accessing the unitialized field by returning early in
> css_rstat_exit() if this is the case.
> 
> Signed-off-by: JP Kobryn <inwardvessel@gmail.com>
> Suggested-by: Michal Koutný <mkoutny@suse.com>
> Fixes: 5da3bfa029d68 ("cgroup: use separate rstat trees for each subsystem")
> Reported-by: syzbot+8d052e8b99e40bc625ed@syzkaller.appspotmail.com
> Acked-by: Shakeel Butt <shakeel.butt@linux.dev>

Applied to cgroup/for-6.17-fixes.

Thanks.

-- 
tejun

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

end of thread, other threads:[~2025-08-09 18:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-07  0:33 [PATCH cgroup/for-6.16-fixes] cgroup: avoid null de-ref in css_rstat_exit() JP Kobryn
2025-08-09 18:46 ` Tejun Heo
  -- strict thread matches above, loose matches on Subject: below --
2025-07-31 19:27 JP Kobryn
2025-08-01 17:38 ` Shakeel Butt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).