Received: by 10.223.185.116 with SMTP id b49csp934697wrg; Wed, 21 Feb 2018 09:15:56 -0800 (PST) X-Google-Smtp-Source: AH8x2245naCfKdi6NokVZsnuGdNyzbxbgP+FnI0CzL4IWh3sMw5UZwVCdYxLqDjPLvcXGOOp3Yzx X-Received: by 10.101.69.9 with SMTP id n9mr3360181pgq.317.1519233356360; Wed, 21 Feb 2018 09:15:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519233356; cv=none; d=google.com; s=arc-20160816; b=BC8yZsAWclYVYoR4rMLt5aEgj7lEV8eCv54A9MK47nNN5mn/NpfUYmLCU8beXkDzJT BKr3D2RhswwrpuEypx4n5ZiTmBk9jLES428YV+Xsi7DV+C5ceuWMD2l4N6+ymTS6iMQI veZN82zSVGvJj7l5DQ/5C8Q6LDag8/alkglelrUM0AS0A8Cxz/h6xH4NZI8LbG5AvYVo tW/XwfAD8x87iuGYSF1NflkxkNLT3XxSUuQ0owv0zLKSRo4NrAcp55OQTU9jaZ7He65o ZQjMGinotpeeT6NuIgK8LID0+U8zFCx7Aqh6CSleKF0cyVQd5Rhs+ZCvRgua523pIcml aE5A== 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=vZkjUDRuSCSRA2oQgEw6xt+M4FpfXhIoQDBgkfykEnA=; b=SOXRBG9XL2jAIlaczR5vzwOGCADp+A7rvwwLJ5dIfzKPQc/zrUaGs1ixBt2W7Dcv6I cYchersllqvdT9AkG78r8N23Xmo7of9rNoLbtjdMDAS1tpBKvjQSECpkng0eEvp2Cm/H cdx/OqV+jXLY3A08ANCEnRb7AsVzgeL/v58dKfQqdfzqa80qf6cM1AIEsjflmMUe5rsj JMqJan4YPAad5WWcUaecalehXKJIdK8r/jjaUgvVK33Gayi8yoOZhzSOTL4CPFWud6Sm 0M2QeiwZAnkHSc5R+TFtgX2srTag0/t2iCLNDGvz3PVJoLdn+Rakw6qFrVWVkEbnkqgJ uhPA== 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 b24-v6si195376pls.222.2018.02.21.09.15.42; Wed, 21 Feb 2018 09:15:56 -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 S934126AbeBUMyr (ORCPT + 99 others); Wed, 21 Feb 2018 07:54:47 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:34174 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934114AbeBUMyp (ORCPT ); Wed, 21 Feb 2018 07:54:45 -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 BC2C91147; Wed, 21 Feb 2018 12:54:44 +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.9 19/77] Btrfs: fix crash due to not cleaning up tree log blocks dirty bits Date: Wed, 21 Feb 2018 13:48:28 +0100 Message-Id: <20180221124432.992166373@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124432.172390020@linuxfoundation.org> References: <20180221124432.172390020@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.9-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 @@ -2463,6 +2463,9 @@ static noinline int walk_down_log_tree(s 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 != @@ -2542,6 +2545,9 @@ static noinline int walk_up_log_tree(str 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); @@ -2618,6 +2624,9 @@ static int walk_log_tree(struct btrfs_tr clean_tree_block(trans, log->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 !=