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 10F45ECAAA1 for ; Tue, 1 Nov 2022 13:18:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229882AbiKANSi (ORCPT ); Tue, 1 Nov 2022 09:18:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229574AbiKANSh (ORCPT ); Tue, 1 Nov 2022 09:18:37 -0400 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2B14C60 for ; Tue, 1 Nov 2022 06:18:34 -0700 (PDT) Received: by verein.lst.de (Postfix, from userid 2407) id 1501D6732D; Tue, 1 Nov 2022 14:18:31 +0100 (CET) Date: Tue, 1 Nov 2022 14:18:30 +0100 From: Christoph Hellwig To: Yu Kuai Cc: Christoph Hellwig , Jens Axboe , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, linux-block@vger.kernel.org, "yukuai (C)" Subject: Re: [PATCH 7/7] block: store the holder kobject in bd_holder_disk Message-ID: <20221101131830.GA16341@lst.de> References: <20221030153120.1045101-1-hch@lst.de> <20221030153120.1045101-8-hch@lst.de> <20221101104927.GA13823@lst.de> <20221101112131.GA14379@lst.de> <57465370-99fe-d8a5-e150-a1057640e972@huaweicloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <57465370-99fe-d8a5-e150-a1057640e972@huaweicloud.com> User-Agent: Mutt/1.5.17 (2007-11-01) Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org On Tue, Nov 01, 2022 at 07:28:17PM +0800, Yu Kuai wrote: > What if bd_holder_dir is already freed here, then uaf can be triggered. > Thus bd_holder_dir need to be resed in del_gendisk() if it's reference > is dropped to 0, however, kobject apis can't do that... Indeed. I don't think we can simply move the dropping of the reference as you suggested as that also implies taking it earlier, and the device in the disk is only initialized in add_disk. Now what I think we could do is: - hold open_mutex in bd_link_disk_holder as you suggested - check that the bdev inode is hashed inside open_mutex before doing the kobject_get