Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp733428rwb; Thu, 22 Sep 2022 05:55:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7nK0yEupkhc+5ckLNQaq9Cstjjkj7HIOdzgV2dJ0AugW+rscQCgfoydw7w8j3p+LPprNKV X-Received: by 2002:a17:907:1b24:b0:76d:7b9d:2f8b with SMTP id mp36-20020a1709071b2400b0076d7b9d2f8bmr2616973ejc.414.1663851341470; Thu, 22 Sep 2022 05:55:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663851341; cv=none; d=google.com; s=arc-20160816; b=C9iudn4IhCLpPViqBcOpFnHxlcT+Vvc4XoCwYOl9eqg8lf/M00IGPhQhRvGr/lXW0J K8N49dSPdia+mS2gwup7gldpRU7VNX5l5JLRnfvQ6I/Ruw6zhhFbo1I+sLd6KSlRHr9m 0gE2czgKxOTV00bR9cNquuS1IlWloqoosR9REVs956ihn2OGTwjHBU3yilB3JtHEy77K MRka58HgSuDJK2ZeEZry/aEBUBqeiBYdcu3+1k3JnFPyV9MKLdWcZ0a/uhTKbI6F04r6 P6CD8wdGBZTrQHg8yHux9ACuNmuGzdkKLfHR2yyp7or53r98qFa2NsPNJEQbE5riblyT zFWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ITFiorsU8QdWseLYwtI2voE8H1QUGXXZpdMvzzvoW7U=; b=mD9cKlMTZsQAb6U73pRYhHRAgwUmY5w+Nb/JzXgJS7s4UV9Bhj8R+4VsykOpiVT8fQ 0YeQLAYlmE5lYcf5fV+TkG/zA5+C54k046CFTsgXiB7qe7ut8kN/S12lv2ntTyl5OLDa F6zN1MQZJpzY2P6JZJVpEYvwzfq09rA7bxNPV+zDE/mBU2j0HMzbjNLAs4onDzrBou3M +qNPIRPv2NVsEcTO8m2a4wBV2B+MS7BAB4wwcnZUdKj0V7a6uOHH4k4xIg+1kAInwCre j4w1D6LTqWlsgAJiw00Nx0KgplcjwII7og/33N2Nwc4x2ZBM8EM5wgnlU/5du1uDHMNM zCaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p26-20020a17090628da00b0073d8659db5csi3964749ejd.966.2022.09.22.05.55.16; Thu, 22 Sep 2022 05:55:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231734AbiIVMx5 (ORCPT + 99 others); Thu, 22 Sep 2022 08:53:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231739AbiIVMxl (ORCPT ); Thu, 22 Sep 2022 08:53:41 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02C55E99AE; Thu, 22 Sep 2022 05:53:28 -0700 (PDT) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MYFTn3lFlzlXJl; Thu, 22 Sep 2022 20:49:17 +0800 (CST) Received: from kwepemm600013.china.huawei.com (7.193.23.68) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 22 Sep 2022 20:53:21 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600013.china.huawei.com (7.193.23.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 22 Sep 2022 20:53:20 +0800 From: Zhihao Cheng To: , , CC: , , , , Subject: [PATCH v2 2/3] quota: Replace all block number checking with helper function Date: Thu, 22 Sep 2022 21:04:00 +0800 Message-ID: <20220922130401.1792256-3-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220922130401.1792256-1-chengzhihao1@huawei.com> References: <20220922130401.1792256-1-chengzhihao1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600013.china.huawei.com (7.193.23.68) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Cleanup all block checking places, replace them with helper function do_check_range(). Signed-off-by: Zhihao Cheng --- fs/quota/quota_tree.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/fs/quota/quota_tree.c b/fs/quota/quota_tree.c index f89186b6db1d..47711e739ddb 100644 --- a/fs/quota/quota_tree.c +++ b/fs/quota/quota_tree.c @@ -71,11 +71,12 @@ static ssize_t write_blk(struct qtree_mem_dqinfo *info, uint blk, char *buf) return ret; } -static inline int do_check_range(struct super_block *sb, uint val, uint max_val) +static inline int do_check_range(struct super_block *sb, uint val, + uint min_val, uint max_val) { - if (val >= max_val) { - quota_error(sb, "Getting block too big (%u >= %u)", - val, max_val); + if (val < min_val || val >= max_val) { + quota_error(sb, "Getting block %u out of range %u-%u", + val, min_val, max_val); return -EUCLEAN; } @@ -89,11 +90,11 @@ static int check_dquot_block_header(struct qtree_mem_dqinfo *info, uint nextblk, prevblk; nextblk = le32_to_cpu(dh->dqdh_next_free); - err = do_check_range(info->dqi_sb, nextblk, info->dqi_blocks); + err = do_check_range(info->dqi_sb, nextblk, 0, info->dqi_blocks); if (err) return err; prevblk = le32_to_cpu(dh->dqdh_prev_free); - err = do_check_range(info->dqi_sb, prevblk, info->dqi_blocks); + err = do_check_range(info->dqi_sb, prevblk, 0, info->dqi_blocks); if (err) return err; @@ -518,12 +519,10 @@ static int remove_tree(struct qtree_mem_dqinfo *info, struct dquot *dquot, goto out_buf; } newblk = le32_to_cpu(ref[get_index(info, dquot->dq_id, depth)]); - if (newblk < QT_TREEOFF || newblk >= info->dqi_blocks) { - quota_error(dquot->dq_sb, "Getting block too big (%u >= %u)", - newblk, info->dqi_blocks); - ret = -EUCLEAN; + ret = do_check_range(dquot->dq_sb, newblk, QT_TREEOFF, + info->dqi_blocks); + if (ret) goto out_buf; - } if (depth == info->dqi_qtree_depth - 1) { ret = free_dqentry(info, dquot, newblk); @@ -624,12 +623,9 @@ static loff_t find_tree_dqentry(struct qtree_mem_dqinfo *info, blk = le32_to_cpu(ref[get_index(info, dquot->dq_id, depth)]); if (!blk) /* No reference? */ goto out_buf; - if (blk < QT_TREEOFF || blk >= info->dqi_blocks) { - quota_error(dquot->dq_sb, "Getting block too big (%u >= %u)", - blk, info->dqi_blocks); - ret = -EUCLEAN; + ret = do_check_range(dquot->dq_sb, blk, QT_TREEOFF, info->dqi_blocks); + if (ret) goto out_buf; - } if (depth < info->dqi_qtree_depth - 1) ret = find_tree_dqentry(info, dquot, blk, depth+1); -- 2.31.1