Received: by 10.223.185.116 with SMTP id b49csp699163wrg; Wed, 21 Feb 2018 05:36:14 -0800 (PST) X-Google-Smtp-Source: AH8x224SzkL/k0PubLwnSlZoIAuWQDWXhRCZwwg8M+SrPK8CTpVofylcoqw6hSXJxhzIaRBCNNte X-Received: by 2002:a17:902:540f:: with SMTP id d15-v6mr3270977pli.224.1519220174297; Wed, 21 Feb 2018 05:36:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519220174; cv=none; d=google.com; s=arc-20160816; b=RVaCqZY4le9G0QYMAk+9ruYzXfTOzkQqVw7EKJeZPjhRc2ZK7eASpgngI2MjeUidL2 MQ5aehmT4IvskwaTIy0muXXcHJsega3Y5euA/6G0YF5dhwDyewxuoXdJ7ePAG6fjGmdN 0fJUEu1rynoxmUpPZ27dcte7mCQVaMxq1GM5elW+WNRFYawGiUbxTHZdLP4AGX06nSiA VpLnJ9EBSORffc1pfKkf/Ykj9T7yZLn6pgsh94uApl2+cF3sqT+IuYlpgj0x9GcEmIx3 h4jsxDov6uwkrfD3zIl77aSKBDHPkRb49YpvzTmOoz2sDnwHlbtufqVPOpmr0mdSA2+T 6hCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=9EdFVSYaorMUNh6JXp+e8Mkfrpuw158akSWVcU4LBRA=; b=ayG0avMZrRdy427OEe1Hvt7IksTehVu+Z9FawWjLP4fgw2ySQUoq6Eh5Zw84mB8TyU tEGIOiwhM4wKBSXRYHfgFY81QXKOGjWY9B5b6oJRz3oTadAK3UAREPlGuN2Ce/NNOqXk ZiCDjFsGZP9YQB6Ptw/cKFEjqKU8+dmL/b1509bmYFISVR/0h957K0khdnAmcLXOboB8 ob5yjC+rNl1e2sCJwoFPQRT3y/CwUypNgOknwcuy2qgF4DKv3z3C3AKnkWLwN0UWY3e+ mInBcFIZKtCrQAf4pl/fZ917tqmkPpcS8wFF9qdX3S2EkKXpfRL4gONh7WOMBqTowrkW pzTA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f91-v6si1222973plf.498.2018.02.21.05.35.59; Wed, 21 Feb 2018 05:36:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754595AbeBUNOi (ORCPT + 99 others); Wed, 21 Feb 2018 08:14:38 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:46028 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965724AbeBUNNW (ORCPT ); Wed, 21 Feb 2018 08:13:22 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 5BC3F1098; Wed, 21 Feb 2018 13:13:21 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liu Bo , Josef Bacik , David Sterba Subject: [PATCH 4.15 136/163] Btrfs: fix crash due to not cleaning up tree log blocks dirty bits Date: Wed, 21 Feb 2018 13:49:25 +0100 Message-Id: <20180221124537.701931714@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124529.931834518@linuxfoundation.org> References: <20180221124529.931834518@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Liu Bo commit 1846430c24d66e85cc58286b3319c82cd54debb2 upstream. In cases that the whole fs flips into readonly status due to failures in critical sections, then log tree's blocks are still dirty, and this leads to a crash during umount time, the crash is about use-after-free, umount -> close_ctree -> stop workers -> iput(btree_inode) -> iput_final -> write_inode_now -> ... -> queue job on stop'd workers cc: v3.12+ Fixes: 681ae50917df ("Btrfs: cleanup reserved space when freeing tree log on error") Signed-off-by: Liu Bo Reviewed-by: Josef Bacik Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/tree-log.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -2494,6 +2494,9 @@ static noinline int walk_down_log_tree(s clean_tree_block(fs_info, next); btrfs_wait_tree_block_writeback(next); btrfs_tree_unlock(next); + } else { + if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &next->bflags)) + clear_extent_buffer_dirty(next); } WARN_ON(root_owner != @@ -2574,6 +2577,9 @@ static noinline int walk_up_log_tree(str clean_tree_block(fs_info, next); btrfs_wait_tree_block_writeback(next); btrfs_tree_unlock(next); + } else { + if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &next->bflags)) + clear_extent_buffer_dirty(next); } WARN_ON(root_owner != BTRFS_TREE_LOG_OBJECTID); @@ -2652,6 +2658,9 @@ static int walk_log_tree(struct btrfs_tr clean_tree_block(fs_info, next); btrfs_wait_tree_block_writeback(next); btrfs_tree_unlock(next); + } else { + if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &next->bflags)) + clear_extent_buffer_dirty(next); } WARN_ON(log->root_key.objectid !=