From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC39C27E045 for ; Tue, 7 Apr 2026 18:59:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775588342; cv=none; b=PNddobpAsHdtVmoO60Jm0hY7rJxpmMQWuwmXlvuLwXyPp5K1kQ5iUAxVp+aTyZ3c5P7JJSoCJKkmliNcNZ28M6sKeFNE/3GLuAxvwl9H7TJFyuDFyaJtJgL/BaZT9xh/KXKSe/iQf+oxaAb5rTWrhFqdRyT9Zdnt3ngXWfl7ddA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775588342; c=relaxed/simple; bh=7vJ9jMGeMr7X77QV7jqBoBmqxtaP15LtHWht7Nl6y5k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SG3d2sREdqamDWI/fRHaT+uym3GeICG5EVMc8VgzC5mwX5358K7Vqa6UDhHKNWz9KQEUZVLCulwgNYmrkAJmEnPK48O8CBXFi2gNCFx5STFUYoPbU5VMXD2akHewL03hbRJZXXwXrfMOO+s0CyvUzcPk/fYmNUXXE2pfFeTWEIA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Y6E6ipuF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Y6E6ipuF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59CA8C116C6; Tue, 7 Apr 2026 18:59:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775588342; bh=7vJ9jMGeMr7X77QV7jqBoBmqxtaP15LtHWht7Nl6y5k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Y6E6ipuFx4CWTU8zcbat0N5qlbKj47bfYnwClJE00nk62V/MQqt8O8Fm7/99NYJe5 dR58xKg3OVRga+9o9SL1DE2JxuoJVnzJm/dV12q1WZ00B1LtSMdnAlTJ3O/dyhrQOd /z4M2wNZC0CBegDddi7sBK4JShxlfLsUFsHkqicNc0RQtY3vp6aYfbKI5aLuzuE2v8 IRI8lyhUUvRXhRaSylPdjm/OHsae/rpTE2WZ7nRfyxU5/yQwgmW1UnlZH36lzDPYU6 KTNTihf80RJwQDpveZzuyVrEjlwFbB8C3q5z+OHziLguGY24OVlzgiR2Bdc5XG7yQc 8dGylM1ow0EWQ== Date: Tue, 7 Apr 2026 08:59:01 -1000 From: Tejun Heo To: Peter Zijlstra Cc: Rik van Riel , linux-kernel@vger.kernel.org, kernel-team@meta.com, Ingo Molnar , Juri Lelli , Vincent Guittot , Steven Rostedt Subject: Re: [PATCH] sched/cpuacct: fix use-after-free in cpuacct_account_field() Message-ID: References: <20260404224742.56d8df3e@fangorn> <20260407075811.GB3738010@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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