Skip to content

Commit ce7fca5

Browse files
kdavemasoncl
authored andcommitted
btrfs: add checks for sys_chunk_array sizes
Verify that possible minimum and maximum size is set, validity of contents is checked in btrfs_read_sys_array. Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
1 parent 75d6ad3 commit ce7fca5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

fs/btrfs/disk-io.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3910,6 +3910,25 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info,
39103910
ret = -EINVAL;
39113911
}
39123912

3913+
/*
3914+
* Obvious sys_chunk_array corruptions, it must hold at least one key
3915+
* and one chunk
3916+
*/
3917+
if (btrfs_super_sys_array_size(sb) > BTRFS_SYSTEM_CHUNK_ARRAY_SIZE) {
3918+
printk(KERN_ERR "BTRFS: system chunk array too big %u > %u\n",
3919+
btrfs_super_sys_array_size(sb),
3920+
BTRFS_SYSTEM_CHUNK_ARRAY_SIZE);
3921+
ret = -EINVAL;
3922+
}
3923+
if (btrfs_super_sys_array_size(sb) < sizeof(struct btrfs_disk_key)
3924+
+ sizeof(struct btrfs_chunk)) {
3925+
printk(KERN_ERR "BTRFS: system chunk array too small %u < %lu\n",
3926+
btrfs_super_sys_array_size(sb),
3927+
sizeof(struct btrfs_disk_key)
3928+
+ sizeof(struct btrfs_chunk));
3929+
ret = -EINVAL;
3930+
}
3931+
39133932
/*
39143933
* The generation is a global counter, we'll trust it more than the others
39153934
* but it's still possible that it's the one that's wrong.

0 commit comments

Comments
 (0)