From patchwork Fri Apr 20 23:59:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 10353883 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A60A660540 for ; Sat, 21 Apr 2018 00:00:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98B8628897 for ; Sat, 21 Apr 2018 00:00:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D5CD288D3; Sat, 21 Apr 2018 00:00:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5207E28897 for ; Sat, 21 Apr 2018 00:00:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753091AbeDTX7p (ORCPT ); Fri, 20 Apr 2018 19:59:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:47246 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752778AbeDTX7M (ORCPT ); Fri, 20 Apr 2018 19:59:12 -0400 Received: from garbanzo.do-not-panic.com (c-73-15-241-2.hsd1.ca.comcast.net [73.15.241.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 38C5821838; Fri, 20 Apr 2018 23:59:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 38C5821838 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=mcgrof@kernel.org From: "Luis R. Rodriguez" To: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org Cc: jack@suse.cz, bart.vanassche@wdc.com, ming.lei@redhat.com, rjw@rjwysocki.net, mguzik@redhat.com, linux-pm@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, "Luis R. Rodriguez" Subject: [PATCH 3/3] fs: fix corner case race on freeze_bdev() when sb disappears Date: Fri, 20 Apr 2018 16:59:04 -0700 Message-Id: <20180420235904.27496-4-mcgrof@kernel.org> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20180420235904.27496-1-mcgrof@kernel.org> References: <20180420235904.27496-1-mcgrof@kernel.org> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP freeze_bdev() will bail but leave the bd_fsfreeze_count incremented if the get_active_super() does not find the superblock on our super_blocks list to match. This issue has been present since v2.6.29 during the introduction of the ioctl_fsfreeze() and ioctl_fsthaw() via commit fcccf502540e3 ("filesystem freeze: implement generic freeze feature"). I am not aware of any existing races which have triggered this situation, however, if it does trigger it could mean leaving a superblock with bd_fsfreeze_count always positive. Fixes: fcccf502540e3 ("filesystem freeze: implement generic freeze feature") Signed-off-by: Luis R. Rodriguez Reviewed-by: Jan Kara --- fs/block_dev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/block_dev.c b/fs/block_dev.c index b54966679833..7a532aa58c07 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -507,8 +507,10 @@ struct super_block *freeze_bdev(struct block_device *bdev) } sb = get_active_super(bdev); - if (!sb) + if (!sb) { + bdev->bd_fsfreeze_count--; goto out; + } if (sb->s_op->freeze_super) error = sb->s_op->freeze_super(sb); else