From: sashiko-bot@kernel.org
To: "Yu Kuai" <yukuai@kernel.org>
Cc: linux-raid@vger.kernel.org, yukuai@fygo.io, tj@kernel.org,
hannes@cmpxchg.org, mkoutny@suse.com, nvdimm@lists.linux.dev
Subject: Re: [RFC PATCH v1 1/3] blk-cgroup: add helpers for bio cgroup state
Date: Tue, 04 Aug 2026 07:08:22 +0000 [thread overview]
Message-ID: <20260804070823.5C0361F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260804065313.2092022-2-yukuai@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Potential Use-After-Free of `cgroup_subsys_state` (css) when re-associating a bio's block cgroup.
--
--- Patch [1]: [RFC PATCH v1 1/3] blk-cgroup: add helpers for bio cgroup state ---
commit 00d4f5448146c9d8e060d7ebf96b61cd64d0f752
Author: Yu Kuai <yukuai@fygo.io>
blk-cgroup: add helpers for bio cgroup state
This commit introduces helpers like bio_blkg() and bio_blkcg() to replace
open-coded cgroup state accesses throughout the block layer. The helpers
are applied to read-side and release paths to prepare for future changes
to bio internal cgroup state storage.
> diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
> index d9676126c5b5d..52e7faaff0e5b 100644
> --- a/block/blk-cgroup.c
> +++ b/block/blk-cgroup.c
> @@ -2113,8 +2113,8 @@ static inline struct blkcg_gq *blkg_tryget_closest(struct bio *bio,
> void bio_associate_blkg_from_css(struct bio *bio,
> struct cgroup_subsys_state *css)
> {
> - if (bio->bi_blkg)
> - blkg_put(bio->bi_blkg);
> + if (bio_blkg(bio))
> + blkg_put(bio_blkg(bio));
>
> if (css && css->parent) {
> bio->bi_blkg = blkg_tryget_closest(bio, css);
> @@ -2141,7 +2141,7 @@ void bio_associate_blkg(struct bio *bio)
> if (blk_op_is_passthrough(bio->bi_opf))
> return;
>
> - if (bio->bi_blkg) {
> + if (bio_blkg(bio)) {
> css = bio_blkcg_css(bio);
> bio_associate_blkg_from_css(bio, css);
[Severity: High]
This is a pre-existing issue, but could this sequence lead to a use-after-free
of the cgroup_subsys_state (css)?
In bio_associate_blkg(), we extract the css pointer from the bio's blkg
without acquiring a new reference or holding an RCU read lock:
bio_associate_blkg()
css = bio_blkcg_css(bio);
bio_associate_blkg_from_css(bio, css);
Then in bio_associate_blkg_from_css(), we immediately drop the bio's blkg
reference:
bio_associate_blkg_from_css()
if (bio_blkg(bio))
blkg_put(bio_blkg(bio));
if (css && css->parent) { <-- potential UAF
If this was the final reference to the blkg (for example, if the cgroup was
removed while I/O was in-flight and a stacked block driver remaps the bio),
the blkg and its css are queued for destruction.
If the thread is preempted right after blkg_put(), could RCU grace periods
pass and the css memory be freed via workqueues before it is dereferenced
at css->parent?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260804065313.2092022-1-yukuai@kernel.org?part=1
next prev parent reply other threads:[~2026-08-04 7:08 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-04 6:53 [RFC PATCH v1 0/3] blk-cgroup: store blkcg in bio before blkcg_mutex conversion Yu Kuai
2026-08-04 6:53 ` [RFC PATCH v1 1/3] blk-cgroup: add helpers for bio cgroup state Yu Kuai
2026-08-04 7:08 ` sashiko-bot [this message]
2026-08-04 10:52 ` Jan Kara
2026-08-04 13:25 ` Christoph Hellwig
2026-08-04 15:07 ` yu kuai
2026-08-04 6:53 ` [RFC PATCH v1 2/3] blk-cgroup: store blkcg in bio instead of blkg Yu Kuai
2026-08-04 7:09 ` sashiko-bot
2026-08-04 9:19 ` Tao Cui
2026-08-04 13:32 ` Christoph Hellwig
2026-08-04 15:30 ` yu kuai
2026-08-04 15:47 ` Christoph Hellwig
2026-08-05 0:58 ` Tao Cui
2026-08-06 9:22 ` Michal Koutný
2026-08-04 6:53 ` [RFC PATCH v1 3/3] blk-cgroup: move async bio punt state to blkcg Yu Kuai
2026-08-04 7:10 ` sashiko-bot
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=20260804070823.5C0361F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-raid@vger.kernel.org \
--cc=mkoutny@suse.com \
--cc=nvdimm@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tj@kernel.org \
--cc=yukuai@fygo.io \
--cc=yukuai@kernel.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