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 X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 196D2C56202 for ; Thu, 26 Nov 2020 17:42:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 75FAB207BC for ; Thu, 26 Nov 2020 17:42:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 75FAB207BC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CBD626B0074; Thu, 26 Nov 2020 12:42:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C6D026B0075; Thu, 26 Nov 2020 12:42:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B34706B0078; Thu, 26 Nov 2020 12:42:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9AF536B0074 for ; Thu, 26 Nov 2020 12:42:43 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 5D5B8180AD807 for ; Thu, 26 Nov 2020 17:42:43 +0000 (UTC) X-FDA: 77527289406.16.sleet37_031813f27381 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 374AC100E6903 for ; Thu, 26 Nov 2020 17:42:43 +0000 (UTC) X-HE-Tag: sleet37_031813f27381 X-Filterd-Recvd-Size: 2298 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Thu, 26 Nov 2020 17:42:42 +0000 (UTC) Received: by verein.lst.de (Postfix, from userid 2407) id 31C9868B05; Thu, 26 Nov 2020 18:42:39 +0100 (CET) Date: Thu, 26 Nov 2020 18:42:38 +0100 From: Christoph Hellwig To: Jan Kara Cc: Christoph Hellwig , Jens Axboe , Tejun Heo , Josef Bacik , Coly Li , Mike Snitzer , Greg Kroah-Hartman , Johannes Thumshirn , dm-devel@redhat.com, Jan Kara , linux-block@vger.kernel.org, linux-bcache@vger.kernel.org, linux-mtd@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 24/44] block: simplify bdev/disk lookup in blkdev_get Message-ID: <20201126174238.GA24098@lst.de> References: <20201126130422.92945-1-hch@lst.de> <20201126130422.92945-25-hch@lst.de> <20201126163341.GL422@quack2.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201126163341.GL422@quack2.suse.cz> User-Agent: Mutt/1.5.17 (2007-11-01) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Nov 26, 2020 at 05:33:41PM +0100, Jan Kara wrote: > > bdev->bd_contains = whole; > > - bdev->bd_part = disk_get_part(disk, partno); > > - if (!(disk->flags & GENHD_FL_UP) || > > - !bdev->bd_part || !bdev->bd_part->nr_sects) { > > + bdev->bd_part = disk_get_part(disk, bdev->bd_partno); > > + if (!bdev->bd_part || !bdev->bd_part->nr_sects) { > > AFAICT it is still possible that we see !(disk->flags & GENHD_FL_UP) here, > isn't it? Is it safe to remove because the nr_sects check is already > equivalent to it? Or something else? At this point we already have the disk abd bdev reference, so we're not closing any new race here. That being said we might as well keep this check to not bother going ahead when the disk is already torn down. > I think bdget() above needs to be already under bdev_lookup_sem. Otherwise > disk_to_dev(bdev->bd_disk)->kobj below is a potential use-after-free. Yes. I've fixed this and the other issues.