btrfs: qgroups: Fix BUG_ON condition in tree level check
authorNikolay Borisov <nborisov@suse.com>
Wed, 12 Jul 2017 06:42:19 +0000 (09:42 +0300)
committerDavid Sterba <dsterba@suse.com>
Wed, 16 Aug 2017 14:12:02 +0000 (16:12 +0200)
The current code was erroneously checking for
root_level > BTRFS_MAX_LEVEL. If we had a root_level of 8 then the check
won't trigger and we could potentially hit a buffer overflow. The
correct check should be root_level >= BTRFS_MAX_LEVEL .

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/qgroup.c

index 4ce351efe2813e101c74658873a25cff434633d6..acb48983be26a838040960920c830c160ba88eb4 100644 (file)
@@ -1603,7 +1603,7 @@ int btrfs_qgroup_trace_subtree(struct btrfs_trans_handle *trans,
        struct extent_buffer *eb = root_eb;
        struct btrfs_path *path = NULL;
 
-       BUG_ON(root_level < 0 || root_level > BTRFS_MAX_LEVEL);
+       BUG_ON(root_level < 0 || root_level >= BTRFS_MAX_LEVEL);
        BUG_ON(root_eb == NULL);
 
        if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags))