From: Tejun Heo <tj@kernel.org>
To: Shakeel Butt <shakeel.butt@linux.dev>
Cc: "Christian Brauner" <brauner@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Chengming Zhou" <zhouchengming@bytedance.com>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Reinette Chatre" <reinette.chatre@intel.com>,
"Babu Moger" <babu.moger@amd.com>,
driver-core@lists.linux.dev, linux-fsdevel@vger.kernel.org,
cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-team@meta.com, stable@vger.kernel.org
Subject: Re: [PATCH] kernfs: check the active count only before a node's first activation
Date: Thu, 03 Dec 2026 09:13:57 -1000 [thread overview]
Message-ID: <2c277706a4a46a7540dbdfeef8a1d225@kernel.org> (raw)
In-Reply-To: <20261203113949.1415267-1-shakeel.butt@linux.dev>
On Thu, Dec 03, 2026 at 03:39:49AM -0800, Shakeel Butt wrote:
> Writing 0 and then 1 to cgroup.pressure hides a cgroup's pressure files
> and shows them again with kernfs_show(). If a PSI trigger is written to
> one of these files at the same time, the show can hit this warning:
>
> WARNING: fs/kernfs/dir.c:1480 at kernfs_activate_one+0xe6/0xf0
> Call Trace:
> kernfs_show+0xa8/0xe0
> cgroup_pressure_write+0x17c/0x220
> cgroup_file_write+0x17f/0x440
> kernfs_fop_write_iter+0x20c/0x2d0
>
> The trigger writer breaks its active protection in cgroup_kn_lock_live()
> and waits for cgroup_mutex. The hide cannot wait for the writer, because
> it holds cgroup_mutex. The writer then takes its reference back with
> kernfs_unbreak_active_protection(), so the hidden node has one active
> reference. If the show runs before the writer drops it,
> kernfs_activate_one() warns. The count is still correct: the writer
> drops the reference when it finishes.
>
> Nothing can hold an active reference before a node's first activation,
> so check the count only then, before the early return, which also
> covers a node that is hidden at that point. resctrl can hit the same
> warning since commit 2d77f9768850 ("fs/resctrl: Prevent deadlock and
> use-after-free in info file handlers"): its info file handlers break
> active protection on files it hides and shows. Commit 071d8e4c2a3b
> ("kernfs: Relax constraint in draining guard") relaxed the same check in
> kernfs_should_drain_open_files().
>
> Tested in a VM with commit 8996b7c8174a ("kernfs: recheck of->released
> after acquiring the active reference") applied, which fixes a separate
> crash in the same test. Six threads write PSI triggers while another
> thread writes 0 and 1 to cgroup.pressure for 15 seconds. Without this
> change the warning fired in all 8 runs, also when an unprivileged user
> does all of it in a delegated cgroup. With it, there was no warning in
> 11 runs, though a debug counter showed the show still found the extra
> reference. The kernfs and cgroup selftests pass.
>
> Fixes: 783bd07d095b ("kernfs: Implement kernfs_show()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Acked-by: Tejun Heo <tj@kernel.org>
Thanks.
--
tejun
prev parent reply other threads:[~2026-12-03 19:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 11:39 [PATCH] kernfs: check the active count only before a node's first activation Shakeel Butt
2026-12-03 19:13 ` Tejun Heo [this message]
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=2c277706a4a46a7540dbdfeef8a1d225@kernel.org \
--to=tj@kernel.org \
--cc=babu.moger@amd.com \
--cc=brauner@kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@meta.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mkoutny@suse.com \
--cc=reinette.chatre@intel.com \
--cc=shakeel.butt@linux.dev \
--cc=stable@vger.kernel.org \
--cc=zhouchengming@bytedance.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.