Skip to content

Commit ecb7c24

Browse files
fdmananakdave
authored andcommitted
btrfs: fix invalid leaf access in btrfs_quota_enable() if ref key not found
If btrfs_search_slot_for_read() returns 1, it means we did not find any key greater than or equals to the key we asked for, meaning we have reached the end of the tree and therefore the path is not valid. If this happens we need to break out of the loop and stop, instead of continuing and accessing an invalid path. Fixes: 5223cc6 ("btrfs: drop the path before adding qgroup items when enabling qgroups") Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 7b54e08 commit ecb7c24

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

fs/btrfs/qgroup.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,11 +1169,14 @@ int btrfs_quota_enable(struct btrfs_fs_info *fs_info,
11691169
}
11701170
if (ret > 0) {
11711171
/*
1172-
* Shouldn't happen, but in case it does we
1173-
* don't need to do the btrfs_next_item, just
1174-
* continue.
1172+
* Shouldn't happen because the key should still
1173+
* be there (return 0), but in case it does it
1174+
* means we have reached the end of the tree -
1175+
* there are no more leaves with items that have
1176+
* a key greater than or equals to @found_key,
1177+
* so just stop the search loop.
11751178
*/
1176-
continue;
1179+
break;
11771180
}
11781181
}
11791182
ret = btrfs_next_item(tree_root, path);

0 commit comments

Comments
 (0)