Commit 5b0798a4 authored by Chris Mason's avatar Chris Mason Committed by Kamal Mostafa

btrfs: fix use after free iterating extrefs

commit dc6c5fb3 upstream.

The code for btrfs inode-resolve has never worked properly for
files with enough hard links to trigger extrefs.  It was trying to
get the leaf out of a path after freeing the path:

	btrfs_release_path(path);
	leaf = path->nodes[0];
	item_size = btrfs_item_size_nr(leaf, slot);

The fix here is to use the extent buffer we cloned just a little higher
up to avoid deadlocks caused by using the leaf in the path.
Signed-off-by: default avatarChris Mason <clm@fb.com>
cc: Mark Fasheh <mfasheh@suse.de>
Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
Reviewed-by: default avatarMark Fasheh <mfasheh@suse.de>
Signed-off-by: default avatarKamal Mostafa <kamal@canonical.com>
parent 210f1fe5
...@@ -1785,7 +1785,6 @@ static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root, ...@@ -1785,7 +1785,6 @@ static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root,
int found = 0; int found = 0;
struct extent_buffer *eb; struct extent_buffer *eb;
struct btrfs_inode_extref *extref; struct btrfs_inode_extref *extref;
struct extent_buffer *leaf;
u32 item_size; u32 item_size;
u32 cur_offset; u32 cur_offset;
unsigned long ptr; unsigned long ptr;
...@@ -1813,9 +1812,8 @@ static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root, ...@@ -1813,9 +1812,8 @@ static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root,
btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK); btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK);
btrfs_release_path(path); btrfs_release_path(path);
leaf = path->nodes[0]; item_size = btrfs_item_size_nr(eb, slot);
item_size = btrfs_item_size_nr(leaf, slot); ptr = btrfs_item_ptr_offset(eb, slot);
ptr = btrfs_item_ptr_offset(leaf, slot);
cur_offset = 0; cur_offset = 0;
while (cur_offset < item_size) { while (cur_offset < item_size) {
...@@ -1829,7 +1827,7 @@ static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root, ...@@ -1829,7 +1827,7 @@ static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root,
if (ret) if (ret)
break; break;
cur_offset += btrfs_inode_extref_name_len(leaf, extref); cur_offset += btrfs_inode_extref_name_len(eb, extref);
cur_offset += sizeof(*extref); cur_offset += sizeof(*extref);
} }
btrfs_tree_read_unlock_blocking(eb); btrfs_tree_read_unlock_blocking(eb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment