Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp425826rwb; Thu, 22 Sep 2022 01:19:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6i3CO343wn3XoKXKJGgMQNz4SAGlcb4kz7lE2J04nYEyjIYIpLqnhBZqA1wkzPS/Rvjxd7 X-Received: by 2002:a17:902:e5c2:b0:178:2eca:9dea with SMTP id u2-20020a170902e5c200b001782eca9deamr2262654plf.73.1663834776032; Thu, 22 Sep 2022 01:19:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663834776; cv=none; d=google.com; s=arc-20160816; b=HiWqFSPaP/m0wGM86u+mWFrjIL7wC2C7teeoJN0FYDZQQW1pySuF0NYVW4jJN1txZw BZztDYyJfqjPzNIwyBpaNPVjGjtTE398d24upnnc3yf47nK5MC+9jVSan5yoJaoFvLlK V/u6xWeoCNxQT0RZAS4R2alNQthAJeL4KdJOi02Ko6ck6hit/g50ld3AHebzDcc5jRUU 1asrzZG0Th7O7W0gLX9ONW/9t170fVtEwQjbg+0mFyeX6vwJfHv27/dF7c82e14Q6W6K seaEAZvCNRHJp++OSo7iaW2VfBQDvolRgurWMX5UBvvtf1KmV15+1Pa42/kU3/KXlG7S 2ezQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=quEt+9hPmSN/UkQMldB294d0OPuAHB9DnGAhwmyn19s=; b=JKsNQrUdtsrloTNKg6br+LsQ4nfbuvCshVpwl4OauXXwCk17cXFWx+X9I88+s8+74u 32qxJlhTV2exE768hHlCt5NhVmeuzerk6H3+ArmktWwGQTnZgh8st70xH52QbL9bRMN6 xGVz53Vwmci/OY4AsrZ41FwKBH4Al2ofq8bGgy6kX1vh7dWtHMiHYuAEe1k3rdo78T1V DFFes5r4ToPoJqDX6ZsQdfaEaczgum8yCOZtoZtCzrdSqmTWe1gD/7vQj113yI7QH56O A/5BsvyBa7W2cfcV9bE9OdwjTesmF/S7fFkOFJwhHms1JI1hHFTqwZdQR2Pk7c3TBA0L TvVw== 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 a9-20020a63d209000000b004394696e659si5331254pgg.150.2022.09.22.01.19.20; Thu, 22 Sep 2022 01:19:36 -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 S229977AbiIVIOF (ORCPT + 99 others); Thu, 22 Sep 2022 04:14:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229819AbiIVIOE (ORCPT ); Thu, 22 Sep 2022 04:14:04 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAA3567CB2; Thu, 22 Sep 2022 01:14:03 -0700 (PDT) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4MY7Kf6d7jzHply; Thu, 22 Sep 2022 16:11:50 +0800 (CST) Received: from kwepemm600013.china.huawei.com (7.193.23.68) by dggemv703-chm.china.huawei.com (10.3.19.46) 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 16:14:01 +0800 Received: from [10.174.178.46] (10.174.178.46) 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 16:14:00 +0800 Subject: Re: [PATCH 1/3] quota: Check next/prev free block number after reading from quota file To: Jan Kara CC: , , , , , , References: <20220820110514.881373-1-chengzhihao1@huawei.com> <20220820110514.881373-2-chengzhihao1@huawei.com> <20220921133715.7tesk3qylombwmyk@quack3> From: Zhihao Cheng Message-ID: <41578612-d582-79ea-bb8e-89fa19d4406e@huawei.com> Date: Thu, 22 Sep 2022 16:13:59 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20220921133715.7tesk3qylombwmyk@quack3> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.46] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600013.china.huawei.com (7.193.23.68) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-6.1 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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 ?? 2022/9/21 21:37, Jan Kara ะด??: Hi Jan, > On Sat 20-08-22 19:05:12, Zhihao Cheng wrote: >> Following process: [...] >> >> Link: https://bugzilla.kernel.org/show_bug.cgi?id=216372 >> Fixes: 1da177e4c3f4152 ("Linux-2.6.12-rc2") > > It's better to just have: > > CC: stable@vger.kernel.org > > here. Fixes tag pointing to kernel release is not very useful. Will add in v2. > >> --- a/fs/quota/quota_tree.c >> +++ b/fs/quota/quota_tree.c >> @@ -71,6 +71,35 @@ 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) >> +{ >> + if (val >= max_val) { >> + quota_error(sb, "Getting block too big (%u >= %u)", >> + val, max_val); >> + return -EUCLEAN; >> + } >> + >> + return 0; >> +} > > I'd already provide min_val and the string for the message here as well (as > you do in patch 2). It is less churn in the next patch and free blocks > checking actually needs that as well. See below. > >> + >> +static int check_free_block(struct qtree_mem_dqinfo *info, >> + struct qt_disk_dqdbheader *dh) >> +{ >> + int err = 0; >> + uint nextblk, prevblk; >> + >> + nextblk = le32_to_cpu(dh->dqdh_next_free); >> + err = do_check_range(info->dqi_sb, nextblk, 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); >> + if (err) >> + return err; > > The free block should actually be > QT_TREEOFF so I'd add the check to > do_check_range(). 'dh->dqdh_next_free' may be updated when quota entry removed, 'dh->dqdh_next_free' can be used for next new quota entris. Before sending v2, I found 'dh->dqdh_next_free' and 'dh->dqdh_prev_free' can easily be zero in newly allocated blocks when continually creating files onwed by different users: find_free_dqentry get_free_dqblk write_blk(info, info->dqi_blocks, buf) // zero'd qt_disk_dqdbheader blk = info->dqi_blocks++ // allocate new one block info->dqi_free_entry = blk // will be used for new quota entries find_free_dqentry if (info->dqi_free_entry) blk = info->dqi_free_entry read_blk(info, blk, buf) // dh->dqdh_next_free = dh->dqdh_prev_free = 0 I think it's normal when 'dh->dqdh_next_free' or 'dh->dqdh_prev_free' equals to 0. > > Also rather than having check_free_block(), I'd provide a helper function > like check_dquot_block_header() which will check only free blocks pointers > now and in later patches you can add other checks there. OK, will be updated in v2. > > Honza >