* [PATCH] Btrfs: fix crash due to not cleaning up tree log block's dirty bits
@ 2018-01-25 18:02 Liu Bo
2018-01-26 14:04 ` Josef Bacik
0 siblings, 1 reply; 2+ messages in thread
From: Liu Bo @ 2018-01-25 18:02 UTC (permalink / raw)
To: linux-btrfs
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: <stable@vger.kernel.org> v3.12+
Fixes: 681ae50917df ("Btrfs: cleanup reserved space when freeing tree log on error")
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/tree-log.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 7bf9b31..22046ed 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -2494,6 +2494,9 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,
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(struct btrfs_trans_handle *trans,
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_trans_handle *trans,
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 !=
--
2.9.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Btrfs: fix crash due to not cleaning up tree log block's dirty bits
2018-01-25 18:02 [PATCH] Btrfs: fix crash due to not cleaning up tree log block's dirty bits Liu Bo
@ 2018-01-26 14:04 ` Josef Bacik
0 siblings, 0 replies; 2+ messages in thread
From: Josef Bacik @ 2018-01-26 14:04 UTC (permalink / raw)
To: Liu Bo; +Cc: linux-btrfs
On Thu, Jan 25, 2018 at 11:02:51AM -0700, Liu Bo wrote:
> 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: <stable@vger.kernel.org> v3.12+
> Fixes: 681ae50917df ("Btrfs: cleanup reserved space when freeing tree log on error")
> Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Thanks,
Josef
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-01-26 14:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-25 18:02 [PATCH] Btrfs: fix crash due to not cleaning up tree log block's dirty bits Liu Bo
2018-01-26 14:04 ` Josef Bacik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).