]> git.hungrycats.org Git - linux/commitdiff
btrfs: Check qgroup level in kernel qgroup assign.
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Fri, 27 Feb 2015 08:24:22 +0000 (16:24 +0800)
committerZygo Blaxell <zblaxell@serenity.furryterror.org>
Fri, 17 Apr 2015 16:00:53 +0000 (12:00 -0400)
Although we have qgroup level check in btrfs-progs, it's not enough
since other programe may still call ioctl directly not using
btrfs-progs. For example, systemd.

But it's btrfs-progs to be blame since we don't provide a
full-function(like subvolume create things) btrfs library with enough
check, and only rely on kernel ioctl.

So Add level checks in kernel too.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Chris Mason <clm@fb.com>
(cherry picked from commit 8465ecec9611d60cbbc8e374ecf68453e0dd5b50)

fs/btrfs/ctree.h
fs/btrfs/qgroup.c

index 5a1861ac0c2454593136921385b7d2bfb3731a2a..8be582c87d8e053d69d8a2b1ae005e5235c2d166 100644 (file)
@@ -1057,6 +1057,12 @@ struct btrfs_block_group_item {
        __le64 flags;
 } __attribute__ ((__packed__));
 
+#define BTRFS_QGROUP_LEVEL_SHIFT               48
+static inline u64 btrfs_qgroup_level(u64 qgroupid)
+{
+       return qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT;
+}
+
 /*
  * is subvolume quota turned on?
  */
index a5f3abbcf58c6dc7fd9fc15c13b5ad11d95491a2..28f085399b78c1289e84837ab293c34853de9966 100644 (file)
@@ -1009,6 +1009,10 @@ int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans,
        struct btrfs_qgroup_list *list;
        int ret = 0;
 
+       /* Check the level of src and dst first */
+       if (btrfs_qgroup_level(src) >= btrfs_qgroup_level(dst))
+               return -EINVAL;
+
        mutex_lock(&fs_info->qgroup_ioctl_lock);
        quota_root = fs_info->quota_root;
        if (!quota_root) {