From: Qu Wenruo <[email protected]>

commit 80e46cf22ba0bcb57b39c7c3b52961ab3a0fd5f2 upstream

Btrfs-progs already have a comprehensive type checker, to ensure there
is only 0 (SINGLE profile) or 1 (DUP/RAID0/1/5/6/10) bit set for chunk
profile bits.

Do the same work for kernel.

Reported-by: Yoon Jungyeon <[email protected]>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=202765
Reviewed-by: Nikolay Borisov <[email protected]>
Reviewed-by: Johannes Thumshirn <[email protected]>
Signed-off-by: Qu Wenruo <[email protected]>
Reviewed-by: David Sterba <[email protected]>
Signed-off-by: David Sterba <[email protected]>
[sudip: manually backport, use btrfs_err with root->fs_info]
Signed-off-by: Sudip Mukherjee <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
 fs/btrfs/volumes.c |    7 +++++++
 1 file changed, 7 insertions(+)

--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -6262,6 +6262,13 @@ static int btrfs_check_chunk_valid(struc
                return -EIO;
        }
 
+       if (!is_power_of_2(type & BTRFS_BLOCK_GROUP_PROFILE_MASK) &&
+           (type & BTRFS_BLOCK_GROUP_PROFILE_MASK) != 0) {
+               btrfs_err(root->fs_info,
+               "invalid chunk profile flag: 0x%llx, expect 0 or 1 bit set",
+                         type & BTRFS_BLOCK_GROUP_PROFILE_MASK);
+               return -EUCLEAN;
+       }
        if ((type & BTRFS_BLOCK_GROUP_TYPE_MASK) == 0) {
                btrfs_err(root->fs_info, "missing chunk type flag: 0x%llx", 
type);
                return -EIO;


Reply via email to