Re: [Kernel Bug] KASAN: slab-use-after-free Read in __blkcg_rstat_flush

From: Ming Lei

Date: Tue Feb 03 2026 - 06:11:48 EST


On Tue, Feb 03, 2026 at 11:54:34AM +0100, Michal Koutný wrote:
> Hello.
>
> On Tue, Feb 03, 2026 at 11:03:01AM +0800, Ming Lei <ming.lei@xxxxxxxxxx> wrote:
> > Can you try the following patch?
>
> I think it'd work thanks to the rcu_read_lock() in
> __blkcg_rstat_flush(). However, the chaining of RCU callbacks makes
> predictability of the release path less deterministic and may be
> unnecessary.

RCU supports this way, here is just 2-stage RCU chain, and everything
is deterministic.

>
> What about this:
>
> index 3cffb68ba5d87..e2f51e3bf04ef 100644
> --- a/tmp/b.c
> +++ b/tmp/a.c
> @@ -1081,6 +1081,7 @@ static void __blkcg_rstat_flush(struct blkcg *blkcg, int cpu)
> smp_mb();
>
> WRITE_ONCE(bisc->lqueued, false);
> + blkg_put(blkg);
> if (bisc == &blkg->iostat)
> goto propagate_up; /* propagate up to parent only */
>
> @@ -2220,8 +2221,10 @@ void blk_cgroup_bio_start(struct bio *bio)
> if (!READ_ONCE(bis->lqueued)) {
> struct llist_head *lhead = this_cpu_ptr(blkcg->lhead);
>
> + blkg_get(bio->bi_blkg);
> llist_add(&bis->lnode, lhead);
> WRITE_ONCE(bis->lqueued, true);
> +

I thought about this way, but ->lqueued is lockless, and in theory the `blkg_iostat_set`
can be added again after WRITE_ONCE(bisc->lqueued, false) happens, so this way looks
fragile.


Thanks,
Ming