From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED20BC43219 for ; Fri, 14 Jan 2022 16:16:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243239AbiANQQQ (ORCPT ); Fri, 14 Jan 2022 11:16:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:47899 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243221AbiANQQG (ORCPT ); Fri, 14 Jan 2022 11:16:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642176965; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Cn45XU5PW6NrZeSvkaw9e57q5ICMQUEETi8oMfHT3VQ=; b=O7NAHrheV7IkIP9aI6O7/ast650N43n1uzSFrta0ePMM1aQgcg5vz4sRIJ4qgMtP7K2lku Alvab6Ue3KQQp89WHQbCw7dqioYqCAP3M1jXslRyIm1wGqJ36xCDKaqGuDWmr27WX+PS1I Kp5wK5BKb3mj0bYH1+Xe6xoHkjd5Y0k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-435-7m0oU4tCPjC_L8zC3OxOvg-1; Fri, 14 Jan 2022 11:16:02 -0500 X-MC-Unique: 7m0oU4tCPjC_L8zC3OxOvg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8B38E18C8C00; Fri, 14 Jan 2022 16:16:00 +0000 (UTC) Received: from T590 (ovpn-8-19.pek2.redhat.com [10.72.8.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 96C89753F8; Fri, 14 Jan 2022 16:15:51 +0000 (UTC) Date: Sat, 15 Jan 2022 00:15:46 +0800 From: Ming Lei To: "Paul E. McKenney" Cc: Boqun Feng , Hillf Danton , syzbot , Joel Fernandes , Lai Jiangshan , linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, quic_neeraju@quicinc.com, frederic@kernel.org, urezki@gmail.com, Jens Axboe Subject: Re: [syzbot] KASAN: use-after-free Read in srcu_invoke_callbacks Message-ID: References: <00000000000081b56205d54c6667@google.com> <20220111134324.1727-1-hdanton@sina.com> <20220111190500.GG947480@paulmck-ThinkPad-P17-Gen-1> <20220114152752.GU947480@paulmck-ThinkPad-P17-Gen-1> <20220114161138.GW947480@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220114161138.GW947480@paulmck-ThinkPad-P17-Gen-1> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 14, 2022 at 08:11:38AM -0800, Paul E. McKenney wrote: > On Fri, Jan 14, 2022 at 11:58:24PM +0800, Ming Lei wrote: > > On Fri, Jan 14, 2022 at 07:27:52AM -0800, Paul E. McKenney wrote: > > > 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. > > > > > > One question for the author and block maintainers... Why not simply have > > > a single srcu_struct for all of the queues? Or is there some situation > > > where you need one queue's reader to avoid blocking other queues' SRCU > > > grace periods? > > > > Because srcu_struct is too fat, and only few drivers need it, and > > most block drivers needn't it. > > Fair points. > > But would it make sense to dynamically allocate a single srcu_struct > when the first need arose, and only remove it when the last need passed? q->srcu is referred in fast IO path, we want to avoid to add indirect reference so not allocating it dynamically. Thanks, Ming