public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@surriel.com>,
	linux-kernel@vger.kernel.org, kernel-team@meta.com,
	Ingo Molnar <mingo@redhat.com>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCH] sched/cpuacct: fix use-after-free in cpuacct_account_field()
Date: Tue, 7 Apr 2026 08:59:01 -1000	[thread overview]
Message-ID: <adVT9Zmm97QUrwW-@slm.duckdns.org> (raw)
In-Reply-To: <20260407075811.GB3738010@noisy.programming.kicks-ass.net>

Hello,

On Tue, Apr 07, 2026 at 09:58:11AM +0200, Peter Zijlstra wrote:
> On Sat, Apr 04, 2026 at 10:47:42PM -0400, Rik van Riel wrote:
> > cpuacct_css_free() calls free_percpu() on ca->cpustat and ca->cpuusage,
> > then kfree(ca). However, a timer interrupt on another CPU can
> > concurrently access this data through cpuacct_account_field(), which
> > walks the cpuacct hierarchy via task_ca()/parent_ca() and performs
> > __this_cpu_add(ca->cpustat->cpustat[index], val).
> > 
> > The race window exists because put_css_set_locked() drops the CSS
> > reference (css_put) before the css_set is RCU-freed (kfree_rcu). This
> > means the CSS percpu_ref can reach zero and trigger the css_free chain
> > while readers obtained the CSS pointer from the old css_set that is
> > still visible via RCU.
> > 
> > Although css_free_rwork_fn is already called after one RCU grace period,
> > the css_set -> CSS reference drop in put_css_set_locked() creates a
> > window where the CSS free chain races with readers still holding the
> > old css_set reference.
> 
> To me this reads like a cgroup fail, not a cpuacct fail per se. But I'm
> forever confused there. TJ?

css_free() is already called after a RCU grace period after the refcnt
reaches zero. The patch is adding another RCU grace period in the path,
which likely is just patching over the underlying problem.

cpuacct_account_field() is called from ticks. The task->cgroups is the RCU
protected pointer to the css_set from which the cpuacct pointer is read.
Each css_set pins the csses that it points to. The cpuacct's refcnt can't
reach zero as long as task->cgroups point to it and if the timer tick is
what's accessing it, the built-in RCU grace period in cgroup core should be
enough.

How reproducible is the problem? Do you have the KASAN report?

Thanks.

-- 
tejun

  reply	other threads:[~2026-04-07 18:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-05  2:47 [PATCH] sched/cpuacct: fix use-after-free in cpuacct_account_field() Rik van Riel
2026-04-07  7:58 ` Peter Zijlstra
2026-04-07 18:59   ` Tejun Heo [this message]
2026-04-08 13:58     ` Rik van Riel

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=adVT9Zmm97QUrwW-@slm.duckdns.org \
    --to=tj@kernel.org \
    --cc=juri.lelli@redhat.com \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=riel@surriel.com \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox