diff options
author | Chris Mason <clm@fb.com> | 2015-10-13 14:06:48 -0400 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2015-10-26 22:38:28 -0400 |
commit | 2849a854224487bc578b73b64422c3cb3ef93ff5 (patch) | |
tree | cecc18105ff992cc0ec13283b28ae6f2c038dd5a /fs/btrfs/backref.c | |
parent | 849ef9286f30c88113906dc35f44a499c0cb385d (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>
Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs/backref.c')
-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 2adc152a32e3..6dcdb2ec9211 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c | |||
@@ -1834,7 +1834,6 @@ static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root, | |||
1834 | int found = 0; | 1834 | int found = 0; |
1835 | struct extent_buffer *eb; | 1835 | struct extent_buffer *eb; |
1836 | struct btrfs_inode_extref *extref; | 1836 | struct btrfs_inode_extref *extref; |
1837 | struct extent_buffer *leaf; | ||
1838 | u32 item_size; | 1837 | u32 item_size; |
1839 | u32 cur_offset; | 1838 | u32 cur_offset; |
1840 | unsigned long ptr; | 1839 | unsigned long ptr; |
@@ -1862,9 +1861,8 @@ static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root, | |||
1862 | btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK); | 1861 | btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK); |
1863 | btrfs_release_path(path); | 1862 | btrfs_release_path(path); |
1864 | 1863 | ||
1865 | leaf = path->nodes[0]; | 1864 | item_size = btrfs_item_size_nr(eb, slot); |
1866 | item_size = btrfs_item_size_nr(leaf, slot); | 1865 | ptr = btrfs_item_ptr_offset(eb, slot); |
1867 | ptr = btrfs_item_ptr_offset(leaf, slot); | ||
1868 | cur_offset = 0; | 1866 | cur_offset = 0; |
1869 | 1867 | ||
1870 | while (cur_offset < item_size) { | 1868 | while (cur_offset < item_size) { |
@@ -1878,7 +1876,7 @@ static int iterate_inode_extrefs(u64 inum, struct btrfs_root *fs_root, | |||
1878 | if (ret) | 1876 | if (ret) |
1879 | break; | 1877 | break; |
1880 | 1878 | ||
1881 | cur_offset += btrfs_inode_extref_name_len(leaf, extref); | 1879 | cur_offset += btrfs_inode_extref_name_len(eb, extref); |
1882 | cur_offset += sizeof(*extref); | 1880 | cur_offset += sizeof(*extref); |
1883 | } | 1881 | } |
1884 | btrfs_tree_read_unlock_blocking(eb); | 1882 | btrfs_tree_read_unlock_blocking(eb); |