Message ID | 1425025468-29749-2-git-send-email-quwenruo@cn.fujitsu.com (mailing list archive) |
---|---|
State | Accepted |
Headers | show |
On 02/27/2015 03:24 AM, Qu Wenruo wrote: > 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> Thanks, Josef -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Fri, Feb 27, 2015 at 04:24:22PM +0800, Qu Wenruo wrote: > 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. The checks should be duplicated in kernel if they are part of the qgroup naming/numbering protocol. The library interface would help programmers to get it right but as there's a direct interface via the ioctls, the checks have to be there regardless. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 0b18070..cbaf1a4 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1056,6 +1056,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? */ diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 48b60db..523e5b2 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -1010,6 +1010,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) {
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> --- fs/btrfs/ctree.h | 6 ++++++ fs/btrfs/qgroup.c | 4 ++++ 2 files changed, 10 insertions(+)