Skip to content

Commit 6141abb

Browse files
fdmananakdave
authored andcommitted
btrfs: move min sys chunk array size check to validate_sys_chunk_array()
We check the minimum size of the sys chunk array in btrfs_validate_super() but we have a better place for that, the helper validate_sys_chunk_array() which we use for every other sys chunk array check. So move it there, also converting the return error from -EINVAL to -EUCLEAN, which is a better fit and also consistent with the other checks. Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent f3da625 commit 6141abb

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

fs/btrfs/disk-io.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,6 +2299,15 @@ static int validate_sys_chunk_array(const struct btrfs_fs_info *fs_info,
22992299
return -EUCLEAN;
23002300
}
23012301

2302+
/* It must hold at least one key and one chunk. */
2303+
if (unlikely(sys_array_size < sizeof(struct btrfs_disk_key) +
2304+
sizeof(struct btrfs_chunk))) {
2305+
btrfs_err(fs_info, "system chunk array too small %u < %zu",
2306+
sys_array_size,
2307+
sizeof(struct btrfs_disk_key) + sizeof(struct btrfs_chunk));
2308+
return -EUCLEAN;
2309+
}
2310+
23022311
while (cur < sys_array_size) {
23032312
struct btrfs_disk_key *disk_key;
23042313
struct btrfs_chunk *chunk;
@@ -2541,19 +2550,6 @@ int btrfs_validate_super(const struct btrfs_fs_info *fs_info,
25412550

25422551
ret = validate_sys_chunk_array(fs_info, sb);
25432552

2544-
/*
2545-
* Obvious sys_chunk_array corruptions, it must hold at least one key
2546-
* and one chunk
2547-
*/
2548-
if (btrfs_super_sys_array_size(sb) < sizeof(struct btrfs_disk_key)
2549-
+ sizeof(struct btrfs_chunk)) {
2550-
btrfs_err(fs_info, "system chunk array too small %u < %zu",
2551-
btrfs_super_sys_array_size(sb),
2552-
sizeof(struct btrfs_disk_key)
2553-
+ sizeof(struct btrfs_chunk));
2554-
ret = -EINVAL;
2555-
}
2556-
25572553
/*
25582554
* The generation is a global counter, we'll trust it more than the others
25592555
* but it's still possible that it's the one that's wrong.

0 commit comments

Comments
 (0)