diff options
author | Chris Mason <clm@fb.com> | 2015-10-13 14:06:48 -0400 |
---|---|---|
committer | Sasha Levin <sasha.levin@oracle.com> | 2015-11-13 13:18:11 -0500 |
commit | 4e2dc9ce572650176e3ce3380ecaf7302547d610 (patch) | |
tree | ef7cdb2563d242f818298aa0bec9e3429bbdbd62 /fs/btrfs | |
parent | e360fb086858344811bdc2f2b4c5ef6396e78179 (diff) | |
download | linux-stable-4e2dc9ce572650176e3ce3380ecaf7302547d610.tar.gz linux-stable-4e2dc9ce572650176e3ce3380ecaf7302547d610.tar.bz2 linux-stable-4e2dc9ce572650176e3ce3380ecaf7302547d610.zip |
btrfs: fix use after free iterating extrefs
[ Upstream commit dc6c5fb3b514221f2e9d21ee626a9d95d3418dff ]
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: Sasha Levin <sasha.levin@oracle.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/backref.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 2d3e32ebfd15..cfd1e6f6ac64 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -1778,7 +1778,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; @@ -1806,9 +1805,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) { @@ -1822,7 +1820,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); |