Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+3 -5
+3 -5
fs/btrfs/backref.c
··· 1828 1828 int found = 0; 1829 1829 struct extent_buffer *eb; 1830 1830 struct btrfs_inode_extref *extref; 1831 - struct extent_buffer *leaf; 1832 1831 u32 item_size; 1833 1832 u32 cur_offset; 1834 1833 unsigned long ptr; ··· 1855 1856 btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK); 1856 1857 btrfs_release_path(path); 1857 1858 1858 - leaf = path->nodes[0]; 1859 - item_size = btrfs_item_size_nr(leaf, slot); 1860 - ptr = btrfs_item_ptr_offset(leaf, slot); 1859 + item_size = btrfs_item_size_nr(eb, slot); 1860 + ptr = btrfs_item_ptr_offset(eb, slot); 1861 1861 cur_offset = 0; 1862 1862 1863 1863 while (cur_offset < item_size) { ··· 1870 1872 if (ret) 1871 1873 break; 1872 1874 1873 - cur_offset += btrfs_inode_extref_name_len(leaf, extref); 1875 + cur_offset += btrfs_inode_extref_name_len(eb, extref); 1874 1876 cur_offset += sizeof(*extref); 1875 1877 } 1876 1878 btrfs_tree_read_unlock_blocking(eb);