Skip to content
/ linux Public

Commit d7cf231

Browse files
fdmananagregkh
authored andcommitted
btrfs: fix invalid leaf access in btrfs_quota_enable() if ref key not found
[ Upstream commit ecb7c24 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6ca11de commit d7cf231

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

fs/btrfs/qgroup.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,11 +1157,14 @@ int btrfs_quota_enable(struct btrfs_fs_info *fs_info,
11571157
}
11581158
if (ret > 0) {
11591159
/*
1160-
* Shouldn't happen, but in case it does we
1161-
* don't need to do the btrfs_next_item, just
1162-
* continue.
1160+
* Shouldn't happen because the key should still
1161+
* be there (return 0), but in case it does it
1162+
* means we have reached the end of the tree -
1163+
* there are no more leaves with items that have
1164+
* a key greater than or equals to @found_key,
1165+
* so just stop the search loop.
11631166
*/
1164-
continue;
1167+
break;
11651168
}
11661169
}
11671170
ret = btrfs_next_item(tree_root, path);

0 commit comments

Comments
 (0)