* [PATCH] btrfs: fix use after free iterating extrefs
@ 2015-10-13 18:06 Chris Mason
2015-10-13 18:50 ` Filipe Manana
2015-10-13 19:17 ` Mark Fasheh
0 siblings, 2 replies; 4+ messages in thread
From: Chris Mason @ 2015-10-13 18:06 UTC (permalink / raw)
To: linux-btrfs, Mark Fasheh, Filipe Manana
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>
---
fs/btrfs/backref.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index ecbc63d..9a2ec79 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,
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;
@@ -1856,9 +1855,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) {
@@ -1872,7 +1870,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);
--
2.4.6
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] btrfs: fix use after free iterating extrefs
2015-10-13 18:06 [PATCH] btrfs: fix use after free iterating extrefs Chris Mason
@ 2015-10-13 18:50 ` Filipe Manana
2015-10-13 19:17 ` Mark Fasheh
1 sibling, 0 replies; 4+ messages in thread
From: Filipe Manana @ 2015-10-13 18:50 UTC (permalink / raw)
To: Chris Mason, linux-btrfs@vger.kernel.org, Mark Fasheh,
Filipe Manana
On Tue, Oct 13, 2015 at 7:06 PM, Chris Mason <clm@fb.com> wrote:
> 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>
Looks good to me.
I failed to notice that problem at commit [1]
[1] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=3fe81ce206f3805e0eb5d886aabbf91064655144
> ---
> fs/btrfs/backref.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
> index ecbc63d..9a2ec79 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,
> 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;
> @@ -1856,9 +1855,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) {
> @@ -1872,7 +1870,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);
> --
> 2.4.6
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Filipe David Manana,
"Reasonable men adapt themselves to the world.
Unreasonable men adapt the world to themselves.
That's why all progress depends on unreasonable men."
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] btrfs: fix use after free iterating extrefs
2015-10-13 18:06 [PATCH] btrfs: fix use after free iterating extrefs Chris Mason
2015-10-13 18:50 ` Filipe Manana
@ 2015-10-13 19:17 ` Mark Fasheh
2015-10-14 2:41 ` Chris Mason
1 sibling, 1 reply; 4+ messages in thread
From: Mark Fasheh @ 2015-10-13 19:17 UTC (permalink / raw)
To: Chris Mason, linux-btrfs, Filipe Manana
On Tue, Oct 13, 2015 at 02:06:48PM -0400, Chris Mason wrote:
> 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: Mark Fasheh <mfasheh@suse.de>
Thanks for the CC Chris.
--Mark
--
Mark Fasheh
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] btrfs: fix use after free iterating extrefs
2015-10-13 19:17 ` Mark Fasheh
@ 2015-10-14 2:41 ` Chris Mason
0 siblings, 0 replies; 4+ messages in thread
From: Chris Mason @ 2015-10-14 2:41 UTC (permalink / raw)
To: Mark Fasheh; +Cc: linux-btrfs, Filipe Manana
On Tue, Oct 13, 2015 at 12:17:55PM -0700, Mark Fasheh wrote:
> On Tue, Oct 13, 2015 at 02:06:48PM -0400, Chris Mason wrote:
> > 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: Mark Fasheh <mfasheh@suse.de>
Thanks Mark and Filipe, I've tested this and queued it up.
-chris
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-10-14 2:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-13 18:06 [PATCH] btrfs: fix use after free iterating extrefs Chris Mason
2015-10-13 18:50 ` Filipe Manana
2015-10-13 19:17 ` Mark Fasheh
2015-10-14 2:41 ` Chris Mason
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).