From patchwork Sun Apr 7 10:50:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 2402891 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id D6B3A40060 for ; Sun, 7 Apr 2013 10:51:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933345Ab3DGKvG (ORCPT ); Sun, 7 Apr 2013 06:51:06 -0400 Received: from mail-pd0-f169.google.com ([209.85.192.169]:52881 "EHLO mail-pd0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933322Ab3DGKvA (ORCPT ); Sun, 7 Apr 2013 06:51:00 -0400 Received: by mail-pd0-f169.google.com with SMTP id 10so2748765pdc.14 for ; Sun, 07 Apr 2013 03:50:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=n9T6ZJGxle9tJFYXy2jGdvtA6RQUVkei1hGHEtSISeg=; b=H1zmukh2BtoKATBUA90apJ9CO55Es9GDpHV7BvKC3jjJuaZSIGb4jKH6K+sGSmiOWW eY8rfezzoD5pXn/68qaEkVX2RZ7L5pM8X0pbgFeqfN/EKTqPGm0W7cWKlHOA8x7pxPIK MO+KtgGHSwxPc/8k0b4V4+bArzn7D3jtEcsboYYWmNVRPf5LbZm0sU35uQTtxfXPGf9F oI14v2Y8W+cGLbWkcPTMnfQTEenBnoICTcm8wYZe2m4kaa2LRNKCvLtkocIkdVE7i5GC tTrDLsPShh/e14LkliZEhpz8ubIelQyY8TaW9jxeY/h9YZ+44d5Vbh7/6PPUegD/qhvk KGcA== X-Received: by 10.66.172.77 with SMTP id ba13mr27149153pac.63.1365331859744; Sun, 07 Apr 2013 03:50:59 -0700 (PDT) Received: from localhost.localdomain.localdomain ([112.2.228.26]) by mx.google.com with ESMTPS id pa2sm27634891pac.9.2013.04.07.03.50.57 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 07 Apr 2013 03:50:59 -0700 (PDT) From: Wang Shilong To: linux-btrfs@vger.kernel.org Cc: wangsl-fnst@cn.fujitsu.com, miaox@cn.fujitsu.com, sensille@gmx.net Subject: [PATCH V3 4/5] Btrfs: fix missing check in the btrfs_qgroup_inherit() Date: Sun, 7 Apr 2013 18:50:19 +0800 Message-Id: <1365331820-973-5-git-send-email-wangshilong1991@gmail.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1365331820-973-1-git-send-email-wangshilong1991@gmail.com> References: <1365331820-973-1-git-send-email-wangshilong1991@gmail.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Wang Shilong The original code forgot to check 'inherit', we should gurantee that all the qgroups in the struct 'inherit' exist. Signed-off-by: Wang Shilong Reviewed-by: Miao Xie --- fs/btrfs/qgroup.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 575e7e4..d0870c8 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -1414,6 +1414,7 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, struct btrfs_qgroup *srcgroup; struct btrfs_qgroup *dstgroup; u32 level_size = 0; + u64 nums; mutex_lock(&fs_info->qgroup_ioctl_lock); if (!fs_info->quota_enabled) @@ -1424,6 +1425,20 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, goto out; } + if (inherit) { + i_qgroups = (u64 *)(inherit + 1); + nums = inherit->num_qgroups + 2 * inherit->num_ref_copies + + 2 * inherit->num_excl_copies; + for (i = 0; i < nums; ++i) { + srcgroup = find_qgroup_rb(fs_info, *i_qgroups); + if (!srcgroup) { + ret = -EINVAL; + goto out; + } + ++i_qgroups; + } + } + /* * create a tracking group for the subvol itself */