From nobody Wed Apr 8 00:00:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F12AFC38A2D for ; Wed, 26 Oct 2022 04:02:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232924AbiJZEB7 (ORCPT ); Wed, 26 Oct 2022 00:01:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232200AbiJZEBY (ORCPT ); Wed, 26 Oct 2022 00:01:24 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92DDB87F92; Tue, 25 Oct 2022 21:01:20 -0700 (PDT) Received: from dggpeml500021.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Mxw3G2F5SzmVPJ; Wed, 26 Oct 2022 11:56:26 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggpeml500021.china.huawei.com (7.185.36.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 26 Oct 2022 12:01:18 +0800 From: Baokun Li To: CC: , , , , , , , Subject: [PATCH v3 2/4] ext4: add helper to check quota inums Date: Wed, 26 Oct 2022 12:23:08 +0800 Message-ID: <20221026042310.3839669-3-libaokun1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221026042310.3839669-1-libaokun1@huawei.com> References: <20221026042310.3839669-1-libaokun1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500021.china.huawei.com (7.185.36.21) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Before quota is enabled, a check on the preset quota inums in ext4_super_block is added to prevent wrong quota inodes from being loaded. In addition, when the quota fails to be enabled, the quota type and quota inum are printed to facilitate fault locating. Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Jason Yan --- fs/ext4/super.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 34b78f380968..0b4060d52d63 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -6885,6 +6885,20 @@ static int ext4_quota_on(struct super_block *sb, int= type, int format_id, return err; } =20 +static inline bool ext4_check_quota_inum(int type, unsigned long qf_inum) +{ + switch (type) { + case USRQUOTA: + return qf_inum =3D=3D EXT4_USR_QUOTA_INO; + case GRPQUOTA: + return qf_inum =3D=3D EXT4_GRP_QUOTA_INO; + case PRJQUOTA: + return qf_inum >=3D EXT4_GOOD_OLD_FIRST_INO; + default: + BUG(); + } +} + static int ext4_quota_enable(struct super_block *sb, int type, int format_= id, unsigned int flags) { @@ -6901,9 +6915,16 @@ static int ext4_quota_enable(struct super_block *sb,= int type, int format_id, if (!qf_inums[type]) return -EPERM; =20 + if (!ext4_check_quota_inum(type, qf_inums[type])) { + ext4_error(sb, "Bad quota inum: %lu, type: %d", + qf_inums[type], type); + return -EUCLEAN; + } + qf_inode =3D ext4_iget(sb, qf_inums[type], EXT4_IGET_SPECIAL); if (IS_ERR(qf_inode)) { - ext4_error(sb, "Bad quota inode # %lu", qf_inums[type]); + ext4_error(sb, "Bad quota inode: %lu, type: %d", + qf_inums[type], type); return PTR_ERR(qf_inode); } =20 @@ -6942,8 +6963,9 @@ int ext4_enable_quotas(struct super_block *sb) if (err) { ext4_warning(sb, "Failed to enable quota tracking " - "(type=3D%d, err=3D%d). Please run " - "e2fsck to fix.", type, err); + "(type=3D%d, err=3D%d, ino=3D%lu). " + "Please run e2fsck to fix.", type, + err, qf_inums[type]); for (type--; type >=3D 0; type--) { struct inode *inode; =20 --=20 2.31.1