Re: [syzbot] KASAN: use-after-free Read in srcu_invoke_callbacks
From: Ming Lei
Date: Fri Jan 14 2022 - 10:55:12 EST
On Fri, Jan 14, 2022 at 10:38:42PM +0800, Boqun Feng wrote:
> Hi,
>
> On Tue, Jan 11, 2022 at 11:05:00AM -0800, Paul E. McKenney wrote:
> [...]
> > > > The buggy address belongs to the object at ffff8880189b5c70
> > > > which belongs to the cache request_queue_srcu of size 3816
>
> This cache name drew my attention when I was trying to look into this,
> because I couldn't find it in v5.16, later on I realized the UAF was
> found in linux-next and the commit introducing the cache was merged into
> mainline if 5.17 merge window:
>
> 704b914f15fb blk-mq: move srcu from blk_mq_hw_ctx to request_queue
>
> I think the UAF is actually a bug introduced by the commit, because in
> that commit srcu structure was moved from blk_mq_hw_ctx to
> request_queue, and therefore the cleanup_srcu_struct() should be moved
> from blk_mq_hw_sysfs_release() to blk_release_queue(), however the above
> commit only deleted the one in blk_mq_hw_sysfs_release() but didn't add
> a new one in blk_release_queue(). As a result when a request queue is
> freed, the srcu structure is not fully clean up, therefore the UAF.
>
> IOW, something like below (untested) should fix this. Copy the auther
> and block maintainers.
>
> Regards,
> Boqun
>
> diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
> index e20eadfcf5c8..10f59416376e 100644
> --- a/block/blk-sysfs.c
> +++ b/block/blk-sysfs.c
> @@ -812,6 +812,10 @@ static void blk_release_queue(struct kobject *kobj)
> bioset_exit(&q->bio_split);
>
> ida_simple_remove(&blk_queue_ida, q->id);
> +
> + if (test_bit(QUEUE_FLAG_HAS_SRCU, &q->queue_flags)) {
> + cleanup_srcu_struct(q->srcu);
> + }
> call_rcu(&q->rcu_head, blk_free_queue_rcu);
> }
Yes, this fix has been posted days ago:
https://lore.kernel.org/linux-block/20220111123401.520192-1-ming.lei@xxxxxxxxxx/T/#u
Thanks,
Ming