Skip to content

Commit b2bd557

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 328c6ec commit b2bd557

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
@@ -1137,11 +1137,14 @@ int btrfs_quota_enable(struct btrfs_fs_info *fs_info,
11371137
}
11381138
if (ret > 0) {
11391139
/*
1140-
* Shouldn't happen, but in case it does we
1141-
* don't need to do the btrfs_next_item, just
1142-
* continue.
1140+
* Shouldn't happen because the key should still
1141+
* be there (return 0), but in case it does it
1142+
* means we have reached the end of the tree -
1143+
* there are no more leaves with items that have
1144+
* a key greater than or equals to @found_key,
1145+
* so just stop the search loop.
11431146
*/
1144-
continue;
1147+
break;
11451148
}
11461149
}
11471150
ret = btrfs_next_item(tree_root, path);

0 commit comments

Comments
 (0)