Re: [PATCH 0/5 cgroup/for-6.16-fixes] harden css_create() for safe placement of call to css_rstat_init()
From: Michal Koutný
Date: Tue Jul 29 2025 - 05:42:47 EST
On Mon, Jul 28, 2025 at 11:04:56AM -0700, JP Kobryn <inwardvessel@xxxxxxxxx> wrote:
> I did consider adding an "initialized" flag to the css but since there can
> be multiple css's per
> cgroup it felt like it would be adding overhead. So I went the path of
> getting the call
> sequence right. I'm open to feedback on this, though.
An implicit flag that builds upon the assumption that css_rstat_init()
must only succeed after it allocates ->rstat_cpu (didn't check gotchas
of this approach with !CONFIG_SMP)
--- a/kernel/cgroup/rstat.c
+++ b/kernel/cgroup/rstat.c
@@ -488,6 +488,10 @@ void css_rstat_exit(struct cgroup_subsys_state *css)
if (!css_uses_rstat(css))
return;
+ /* Incomplete css whose css_rstat_init failed */
+ if (!css->rstat_cpu)
+ return;
+
css_rstat_flush(css);
/* sanity check */
Attachment:
signature.asc
Description: PGP signature