diff options
author | Chris Mason <clm@fb.com> | 2015-10-13 14:06:48 -0400 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2015-10-13 21:54:44 -0400 |
commit | dc6c5fb3b514221f2e9d21ee626a9d95d3418dff (patch) | |
tree | 1717fc340050baa6b07d20273bcfc457fd55e1b9 | |
parent | 8eb934591f8bf584969454a658f629cd06e59f3a (diff) |
btrfs: fix use after free iterating extrefs
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>
-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 ecbc63d3143e..9a2ec79e8cfb 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c | |||
@@ -1828,7 +1828,6 @@ static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root, | |||
1828 | int found = 0; | 1828 | int found = 0; |
1829 | struct extent_buffer *eb; | 1829 | struct extent_buffer *eb; |
1830 | struct btrfs_inode_extref *extref; | 1830 | struct btrfs_inode_extref *extref; |
1831 | struct extent_buffer *leaf; | ||
1832 | u32 item_size; | 1831 | u32 item_size; |
1833 | u32 cur_offset; | 1832 | u32 cur_offset; |
1834 | unsigned long ptr; | 1833 | unsigned long ptr; |
@@ -1856,9 +1855,8 @@ static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root, | |||
1856 | btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK); | 1855 | btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK); |
1857 | btrfs_release_path(path); | 1856 | btrfs_release_path(path); |
1858 | 1857 | ||
1859 | leaf = path->nodes[0]; | 1858 | item_size = btrfs_item_size_nr(eb, slot); |
1860 | item_size = btrfs_item_size_nr(leaf, slot); | 1859 | ptr = btrfs_item_ptr_offset(eb, slot); |
1861 | ptr = btrfs_item_ptr_offset(leaf, slot); | ||
1862 | cur_offset = 0; | 1860 | cur_offset = 0; |
1863 | 1861 | ||
1864 | while (cur_offset < item_size) { | 1862 | while (cur_offset < item_size) { |
@@ -1872,7 +1870,7 @@ static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root, | |||
1872 | if (ret) | 1870 | if (ret) |
1873 | break; | 1871 | break; |
1874 | 1872 | ||
1875 | cur_offset += btrfs_inode_extref_name_len(leaf, extref); | 1873 | cur_offset += btrfs_inode_extref_name_len(eb, extref); |
1876 | cur_offset += sizeof(*extref); | 1874 | cur_offset += sizeof(*extref); |
1877 | } | 1875 | } |
1878 | btrfs_tree_read_unlock_blocking(eb); | 1876 | btrfs_tree_read_unlock_blocking(eb); |