Skip to content

Commit e7764bc

Browse files
josefbacikgregkh
authored andcommitted
btrfs: check the root node for uptodate before returning it
commit 120de40 upstream. Now that we clear the extent buffer uptodate if we fail to write it out we need to check to see if our root node is uptodate before we search down it. Otherwise we could return stale data (or potentially corrupt data that was caught by the write verification step) and think that the path is OK to search down. CC: stable@vger.kernel.org # 5.4+ Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 09e0ef2 commit e7764bc

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

‎fs/btrfs/ctree.c‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,12 +2589,9 @@ static struct extent_buffer *btrfs_search_slot_get_root(struct btrfs_root *root,
25892589
{
25902590
struct btrfs_fs_info *fs_info = root->fs_info;
25912591
struct extent_buffer *b;
2592-
int root_lock;
2592+
int root_lock = 0;
25932593
int level = 0;
25942594

2595-
/* We try very hard to do read locks on the root */
2596-
root_lock = BTRFS_READ_LOCK;
2597-
25982595
if (p->search_commit_root) {
25992596
/*
26002597
* The commit roots are read only so we always do read locks,
@@ -2632,6 +2629,9 @@ static struct extent_buffer *btrfs_search_slot_get_root(struct btrfs_root *root,
26322629
goto out;
26332630
}
26342631

2632+
/* We try very hard to do read locks on the root */
2633+
root_lock = BTRFS_READ_LOCK;
2634+
26352635
/*
26362636
* If the level is set to maximum, we can skip trying to get the read
26372637
* lock.
@@ -2658,6 +2658,17 @@ static struct extent_buffer *btrfs_search_slot_get_root(struct btrfs_root *root,
26582658
level = btrfs_header_level(b);
26592659

26602660
out:
2661+
/*
2662+
* The root may have failed to write out at some point, and thus is no
2663+
* longer valid, return an error in this case.
2664+
*/
2665+
if (!extent_buffer_uptodate(b)) {
2666+
if (root_lock)
2667+
btrfs_tree_unlock_rw(b, root_lock);
2668+
free_extent_buffer(b);
2669+
return ERR_PTR(-EIO);
2670+
}
2671+
26612672
p->nodes[level] = b;
26622673
if (!p->skip_locking)
26632674
p->locks[level] = root_lock;

0 commit comments

Comments
 (0)