Skip to content

Commit

Permalink
btrfs: fix use after free iterating extrefs
Browse files Browse the repository at this point in the history
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: Chris Mason <clm@fb.com>
cc: stable@vger.kernel.org # v3.7+
cc: Mark Fasheh <mfasheh@suse.de>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: Chris Mason <clm@fb.com>
  • Loading branch information
Chris Mason committed Oct 27, 2015
1 parent 849ef92 commit 2849a85
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions fs/btrfs/backref.c
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,6 @@ static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root,
int found = 0;
struct extent_buffer *eb;
struct btrfs_inode_extref *extref;
struct extent_buffer *leaf;
u32 item_size;
u32 cur_offset;
unsigned long ptr;
Expand Down Expand Up @@ -1862,9 +1861,8 @@ static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root,
btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK);
btrfs_release_path(path);

leaf = path->nodes[0];
item_size = btrfs_item_size_nr(leaf, slot);
ptr = btrfs_item_ptr_offset(leaf, slot);
item_size = btrfs_item_size_nr(eb, slot);
ptr = btrfs_item_ptr_offset(eb, slot);
cur_offset = 0;

while (cur_offset < item_size) {
Expand All @@ -1878,7 +1876,7 @@ static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root,
if (ret)
break;

cur_offset += btrfs_inode_extref_name_len(leaf, extref);
cur_offset += btrfs_inode_extref_name_len(eb, extref);
cur_offset += sizeof(*extref);
}
btrfs_tree_read_unlock_blocking(eb);
Expand Down

0 comments on commit 2849a85

Please sign in to comment.