Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934474AbcCOIXc (ORCPT ); Tue, 15 Mar 2016 04:23:32 -0400 Received: from mx2.suse.de ([195.135.220.15]:59838 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933849AbcCOIX2 (ORCPT ); Tue, 15 Mar 2016 04:23:28 -0400 Date: Tue, 15 Mar 2016 09:23:50 +0100 From: Jan Kara To: Rabin Vincent Cc: Jan Kara , Rabin Vincent , viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, axboe@kernel.dk, hch@lst.de Subject: Re: [PATCH] block: protect iterate_bdevs() against concurrent close Message-ID: <20160315082350.GA17942@quack.suse.cz> References: <1457612763-23196-1-git-send-email-rabin.vincent@axis.com> <20160310173727.GA19795@quack.suse.cz> <20160314174258.GA16571@debian> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160314174258.GA16571@debian> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1289 Lines: 29 On Mon 14-03-16 18:42:58, Rabin Vincent wrote: > (fixed Jens' address) > > On Thu, Mar 10, 2016 at 06:37:27PM +0100, Jan Kara wrote: > > On Thu 10-03-16 13:26:03, Rabin Vincent wrote: > > > If a block device is closed while iterate_bdevs() is handling it, the > > > following NULL pointer dereference occurs because bdev->b_disk is NULL > > > in bdev_get_queue(), which is called from blk_get_backing_dev_info() (in > > > turn called by the mapping_cap_writeback_dirty() call in > > > __filemap_fdatawrite_range()): > > > > Thanks for spotting the problem. The patch will fix the problem you > > found. But what prevents e.g. flusher thread from trying to writeback > > the block device inode while that gets invalidated at the same moment? > > Don't the sync_block_dev() / bdev_write_inode() calls in __blkdev_put() > prevent this? They don't. They make sure all dirty data is written but flusher thread can still be in the middle of iteration over block device pages. So flusher thread may still hold reference to the block device inode while __blkdev_put() is done with it. Although flusher has nothing to write anymore, it can still call some function where using inode_to_bdi() will result in NULL pointer dereference... Honza -- Jan Kara SUSE Labs, CR