From: sashiko-bot@kernel.org
To: "Yu Kuai" <yukuai@kernel.org>
Cc: hannes@cmpxchg.org, nvdimm@lists.linux.dev, yukuai@fygo.io,
linux-raid@vger.kernel.org, tj@kernel.org, mkoutny@suse.com
Subject: Re: [RFC PATCH v1 3/3] blk-cgroup: move async bio punt state to blkcg
Date: Tue, 04 Aug 2026 07:10:41 +0000 [thread overview]
Message-ID: <20260804071042.695571F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260804065313.2092022-4-yukuai@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] A race condition in `blkcg_punt_bio_submit()` allows a use-after-free on `struct blkcg` because `queue_work()` is called after dropping the lock without holding a local reference to the cgroup.
--
--- Patch [3]: [RFC PATCH v1 3/3] blk-cgroup: move async bio punt state to blkcg ---
commit 0ed7c55259ed7cd55caede491e674b21be72ca58
Author: Yu Kuai <yukuai@fygo.io>
blk-cgroup: move async bio punt state to blkcg
This commit moves the async bio punt state from blkg to blkcg.
This preserves priority-inversion avoidance while preventing
blkcg_punt_bio_submit() from creating blkgs that are not needed
by any policy.
> diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
> index 68a1d93e6584e..a70f92f1541b1 100644
> --- a/block/blk-cgroup.c
> +++ b/block/blk-cgroup.c
[ ... ]
> @@ -239,15 +234,15 @@ static void blkg_async_bio_workfn(struct work_struct *work)
> */
> void blkcg_punt_bio_submit(struct bio *bio)
> {
> - struct blkcg_gq *blkg = bio_blkg(bio);
> + struct blkcg *blkcg = bio_blkcg(bio);
>
> - if (blkg && blkg->parent) {
> - spin_lock(&blkg->async_bio_lock);
> - bio_list_add(&blkg->async_bios, bio);
> - spin_unlock(&blkg->async_bio_lock);
> - queue_work(blkcg_punt_bio_wq, &blkg->async_bio_work);
> + if (blkcg && cgroup_parent(blkcg->css.cgroup)) {
> + spin_lock(&blkcg->async_bio_lock);
> + bio_list_add(&blkcg->async_bios, bio);
> + spin_unlock(&blkcg->async_bio_lock);
> + queue_work(blkcg_punt_bio_wq, &blkcg->async_bio_work);
[Severity: High]
This is a pre-existing issue, but could this race window between
spin_unlock() and queue_work() lead to a use-after-free on the blkcg structure?
If Thread A calls blkcg_punt_bio_submit(), places the bio into async_bios
under the spinlock, and is then preempted right after unlocking:
Thread A:
spin_unlock(&blkcg->async_bio_lock);
<preempted>
A concurrent worker thread might awaken, acquire the lock, extract the
newly added bio, and submit it. If the bio completes very quickly, it will
drop its css reference.
If this was the last reference keeping blkcg alive (e.g. if the cgroup was
being deleted), blkcg_css_free() could execute and free the blkcg:
blkcg_css_free()
...
free_percpu(blkcg->lhead);
kfree(blkcg);
When Thread A resumes, wouldn't it execute queue_work() on the freed blkcg
memory?
> } else {
> - /* Never bounce if there is no non-root blkg to queue on. */
> + /* Never bounce if there is no non-root blkcg to queue on. */
> submit_bio(bio);
> }
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260804065313.2092022-1-yukuai@kernel.org?part=3
prev parent reply other threads:[~2026-08-04 7:10 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
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 [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=20260804071042.695571F000E9@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