Skip to content

Commit eea51c6

Browse files
inwardvesselhtejun
authored andcommitted
cgroup: avoid null de-ref in css_rstat_exit()
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 <[email protected]> Suggested-by: Michal Koutný <[email protected]> Fixes: 5da3bfa ("cgroup: use separate rstat trees for each subsystem") Cc: [email protected] # v6.16 Reported-by: [email protected] Acked-by: Shakeel Butt <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 87eba5b commit eea51c6

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

kernel/cgroup/rstat.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ void css_rstat_exit(struct cgroup_subsys_state *css)
479479
if (!css_uses_rstat(css))
480480
return;
481481

482+
if (!css->rstat_cpu)
483+
return;
484+
482485
css_rstat_flush(css);
483486

484487
/* sanity check */

0 commit comments

Comments
 (0)