From patchwork Thu Feb 23 07:32:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5p2O5oms6Z+s?= X-Patchwork-Id: 60820 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp188381wrd; Wed, 22 Feb 2023 23:53:01 -0800 (PST) X-Google-Smtp-Source: AK7set+pgTTM8l5tButDPTQGeorOKMv4GWES6xy5L/DDp4QUbrd/OdvMbJp5KfYKPBNaitaMVCWW X-Received: by 2002:a05:6a20:7da9:b0:c7:7a94:f11 with SMTP id v41-20020a056a207da900b000c77a940f11mr13628691pzj.0.1677138781155; Wed, 22 Feb 2023 23:53:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1677138781; cv=pass; d=google.com; s=arc-20160816; b=sjIgC+jICuvpPjBzVWFf8VcwHGkPw9gjjKyfjbc/ILpGEyAFu0lISryzLnppEmFVBL 32pphOcRGXePdoBYIGRf5hn/YIUuh5ritgr7tP62OovaihjjjMhOaLHkU+mdojIK658U ZtCp7QmMlGnNZeb9PDHi0j0TuZ6xsoTmqM0Twdb1Z9VEbDi7zdXGl+NtP80K5HpjcfCI fE8leHvUuy+xlAGBeb9nDfzpyTdBiPhcR3mnr2TAlgcbDT7Z2MunGOPz5NBKa3XOiOEu aABTrW09TH/UquViE5TPKWukm8VNqXm80WIMqPOFPSvRUeZ7ahKojWcTFw+3neAj0AhQ Kx7w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=faW3HhIAR1MlfDaocGw3VLd9DV5LRNDAzL7XApSVfW0=; b=MbDQgsDol9+VzXf58QgS3kWaWwX4r5ZWHRAIAwTyLVZwS5UpSyNN0ecv3JucVSzUYl WHtNr27VS4WmukkYKnBM4SM1ziDm9GcE7cCRS/UmebLXnQev/KwYUK84217m5A0FGNY0 oV+U62QkrxDUGs6dPh6+VO/ZvBj7N/WoklYmJp/rTOojlNFKz1nVVApWgTllXZ9ssA9R r51zMnTapvgWF5AiUtf+z7/v2UCmSBnY7GFhKOqaKEGnEUlTK0ZqOP9G3DH1TG+jtCtW 09MTAMjAquXAuBC0sR+dskngriCQS/V5kBb38QSrxpS9vC/8FFKUm9CFLq2MBqlAiDnN nshw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=Co9UnSWk; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w29-20020a63161d000000b00502f145822bsi2158201pgl.345.2023.02.22.23.52.48; Wed, 22 Feb 2023 23:53:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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; dkim=pass header.i=@vivo.com header.s=selector2 header.b=Co9UnSWk; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233492AbjBWHco (ORCPT + 99 others); Thu, 23 Feb 2023 02:32:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjBWHcl (ORCPT ); Thu, 23 Feb 2023 02:32:41 -0500 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2136.outbound.protection.outlook.com [40.107.215.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 159614AFF5 for ; Wed, 22 Feb 2023 23:32:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CLf+SLD6FWo5Q7JeAD19sPtS/PFBif8GwUbE+zjB5CMD5YFInEt8B4+FIw0Frk0QtgIHet8z//onKTOkDgUQQDx73uBYI11J0el9WqqMh+B3btuWcjiVxCZT1NF8b31iE/MklMjiqCK8hzNTX3cz4PgD+ZTMTQlQiv6vT7Qcv9h6NdN25HfHZNewRNUmSUV7Tejr4NcgPbCelvkWtwVJfsUqwn12isBg7Qetsw6SHN0clw0CICRqAsz8KFJmMR6OK31qa1pH81NM5TsuYcnfKwJkvuVNS1yV+cxJpQoEMGJwGULlzDPIulNuWWZxzWBhrX9QgwJPP76cW78/prmOJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=faW3HhIAR1MlfDaocGw3VLd9DV5LRNDAzL7XApSVfW0=; b=P3YC4cUtGVNxGLC2uICMGS9qnRj/E8wjF5aXh9gpxwfe4FUBWkXt8wvqxa1S3okDMLQJ7qwdhjUemyAfquCeDEW9UmvbTxSS9y+TfVgr+j110lr3cJZe5hWotzQg3+lxC3eJqqLQTPWX/XreYxKyXCzfAQDg/gvYxgV3vZ3sI9pg/p4xtEavHeuhyOIl9tBQvhoUu+e7cOXYJ9OnOvCAVx7JUTv0J5F/ujRv43Sef1QThWUDr/D9jaLPy4gCDgGW70l14Juh2Qw1gbiP3EjKqjUlE2ruifH4cc3EnTFITBKn2xFW96S1xiHqY2yewc6CNmPCNu//i2SCyPY+MFF6XQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=faW3HhIAR1MlfDaocGw3VLd9DV5LRNDAzL7XApSVfW0=; b=Co9UnSWkq9LC/xoGvrEFD4map7w2+CEtjzLobzY+YJT+a0DyuZ5XsUB4cfctZVeYOGsDtlav6M4+Vn79x8QK7EvcHLNTsKX/M1iIakQhp+XDq9GMCMj307S8XWP/bBA4M+htDs0pMk87t3ipG1hujJd9NcCOY4jhqlovi/7jq++jhYBx45SYtaVd6PRjsQWZA1bWpyxn4iSE4xqA5evGW0EcQrOW/uDl8w1rYqOY4u0NyO7KRTrRIJ9xxFmjOO0vZ3tgX1d+JAsQdz1bjBSQhKJBLbkHVirgVt/eoWvPo78uBclbhN1n8PKTQ12FCyQsFdyWCo98JEH1hDp+SWxA2g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from TYZPR06MB5275.apcprd06.prod.outlook.com (2603:1096:400:1f5::6) by SEZPR06MB5024.apcprd06.prod.outlook.com (2603:1096:101:46::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.14; Thu, 23 Feb 2023 07:32:35 +0000 Received: from TYZPR06MB5275.apcprd06.prod.outlook.com ([fe80::a2c6:4a08:7779:5190]) by TYZPR06MB5275.apcprd06.prod.outlook.com ([fe80::a2c6:4a08:7779:5190%4]) with mapi id 15.20.6134.019; Thu, 23 Feb 2023 07:32:35 +0000 From: Yangtao Li To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Yangtao Li Subject: [PATCH] f2fs: fix to check quota inums Date: Thu, 23 Feb 2023 15:32:22 +0800 Message-Id: <20230223073222.81702-1-frank.li@vivo.com> X-Mailer: git-send-email 2.35.1 X-ClientProxiedBy: SG2PR01CA0179.apcprd01.prod.exchangelabs.com (2603:1096:4:28::35) To TYZPR06MB5275.apcprd06.prod.outlook.com (2603:1096:400:1f5::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYZPR06MB5275:EE_|SEZPR06MB5024:EE_ X-MS-Office365-Filtering-Correlation-Id: 3e477709-417b-4102-928d-08db157021a9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EpPkTFJNKEIemfMkr+89hlVVcnxlLZ/7BzrydEkDZYkn9v2W897cTbo87CD3n13PD0WjuCEKZIC57kP5b+bRgZViUXh/NCvI4nn4KVcd8uXt7AXloUEuiawZ1r0PIjJ4ijg0490qwdPuwH3nV9o0ZdPwjD/ucqwWs98wl7X6VCBhFviXRfWN4qa4UqeS4k0WVraqt2vHQkCP5OeWbiKEISD5Euu6LS0a7OkwQlU6CvRE5mXvpTr1EobcS0wCDuZeQvXYbkR0BUyrc8oM1j/2UCZq4QNFB+Lfi56ZxUWIUOL7x3WyN4cVyZPXhkj+ikfrMILVbbAcs+dHD+BXLk8Stf+Ftv/IAbisdwkpJBvimhtXMUTHtj3TOWVk0sMAoZP9ga1SKxZPh0IwownBGvpRv7oNmiGGSAKhifZjnCmMHlwhK87UbmKXPN8t6+LE5o3CwqWNAlfhK9DBWTQZnoYEr91wcFvZMfFpWK3tNfZ1mpPCWxqooqZSg6J1PyKH/DYjlnypNERsIE9rXxNqCFQi0aN+L3mFIWqJh4Nbeg5Uap+a/8xmP+okx/MVuuYr8K33yPRVnCHxHrt42cV7ZZRmuFuellJFSNxnfZSrqiqR3mZamqTbWApgC6dZ9UYYFsUU9IrxcHhzacIH1SPL4ExGjjWlgk7uvPieXtdmTUjf/MWTaZBpEGuHGKQZ1PVs6HbWrsVNMaQ/xC/czrP8rOakKQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:TYZPR06MB5275.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(136003)(366004)(396003)(39860400002)(376002)(346002)(451199018)(4326008)(8676002)(36756003)(6506007)(38100700002)(66556008)(66476007)(1076003)(186003)(26005)(6512007)(107886003)(478600001)(8936002)(52116002)(41300700001)(316002)(86362001)(83380400001)(6486002)(5660300002)(66946007)(6666004)(38350700002)(2906002)(15650500001)(2616005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7pKH/lS/CxR06suh3HjAoawPKxQLWbZgdM/F1Kh3Rkcj2YhinSmmKk5uLdojk7gfprztKE6+RhllCsnBd1s8cbtuKEmnSba9i/uqjoJWUJdAJym0jak6KzSxe+JpzS8pkIn01Ai4e59AuczaqSSA2NTzNVDz/ulSNs3FKaU5ZsXcui1R2bELft50YuYL4GfHiMIha3gZWcPeCnTyQivgrUbYhrVizE+dAb6FHap6y91YrDEGhi2iUHpkY0jeZWNMxdusVu7tLXZuegcPu5qMGNG5nxaauuohjCOPLh/rRn8zA0b701l1gKQNjEahJCy6LwU7M1ytBa+4Kbj7H5uljPfeT9A2TQHgLnF2INqN2P+pfh6IjL6j59T3UK9kxYXYUZBsFEysIO1HxNJoK70Uwv/SkXAxv9fQIs+Z8lrs0+FTmfHzJ2HXVYrRWfa7nvZbq0w/jpL1Zzu6BLZZucyK33eEhhkzx6xVlU43ymlNcy0cWko4HR2tjqna9GUWRarcPmgyQbCj8IMaMTcfFKePvxTobVkHj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.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e477709-417b-4102-928d-08db157021a9 X-MS-Exchange-CrossTenant-AuthSource: TYZPR06MB5275.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Feb 2023 07:32:35.0369 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: eFOjdYUPWNIBQ4P2xh2EJ2K0Nok43z57mq1djmA6MxYHp384GIiz7tHahzS6tvfJ1BRH8lHkWZ4bflkPCZqFIA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR06MB5024 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758607474361814489?= X-GMAIL-MSGID: =?utf-8?q?1758607474361814489?= We should check quota file ino before enable quota, and not only 0. BTW fix following check error: WARNING: Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants. Fixes: ea6767337f86 ("f2fs: support quota sys files") Signed-off-by: Yangtao Li --- fs/f2fs/super.c | 54 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index aa55dc12aff2..c7e0639892e2 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -2652,22 +2652,40 @@ int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly) return enabled; } +static inline bool f2fs_check_quota_inum(int type, unsigned long qf_inum) +{ + switch (type) { + case USRQUOTA: + return qf_inum == 4; + case GRPQUOTA: + return qf_inum == 5; + case PRJQUOTA: + return qf_inum == 6; + default: + return false; + } +} + static int f2fs_quota_enable(struct super_block *sb, int type, int format_id, unsigned int flags) { + struct f2fs_sb_info *sbi = F2FS_SB(sb); struct inode *qf_inode; unsigned long qf_inum; int err; - BUG_ON(!f2fs_sb_has_quota_ino(F2FS_SB(sb))); + f2fs_bug_on(sbi, !f2fs_sb_has_quota_ino(sbi)); qf_inum = f2fs_qf_ino(sb, type); - if (!qf_inum) - return -EPERM; + if (!f2fs_check_quota_inum(type, qf_inum)) { + f2fs_err(sbi, "Bad quota inum: %lu, type: %d", + qf_inum, type); + return -EFSCORRUPTED; + } qf_inode = f2fs_iget(sb, qf_inum); if (IS_ERR(qf_inode)) { - f2fs_err(F2FS_SB(sb), "Bad quota inode %u:%lu", type, qf_inum); + f2fs_err(sbi, "Bad quota inode %u:%lu", type, qf_inum); return PTR_ERR(qf_inode); } @@ -2682,7 +2700,7 @@ static int f2fs_enable_quotas(struct super_block *sb) { struct f2fs_sb_info *sbi = F2FS_SB(sb); int type, err = 0; - unsigned long qf_inum; + char count = MAXQUOTAS; bool quota_mopt[MAXQUOTAS] = { test_opt(sbi, USRQUOTA), test_opt(sbi, GRPQUOTA), @@ -2696,21 +2714,21 @@ static int f2fs_enable_quotas(struct super_block *sb) sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE; - for (type = 0; type < MAXQUOTAS; type++) { - qf_inum = f2fs_qf_ino(sb, type); - if (qf_inum) { - err = f2fs_quota_enable(sb, type, QFMT_VFS_V1, + if (!f2fs_sb_has_project_quota(sbi)) + count--; + + for (type = 0; type < count; type++) { + err = f2fs_quota_enable(sb, type, QFMT_VFS_V1, DQUOT_USAGE_ENABLED | (quota_mopt[type] ? DQUOT_LIMITS_ENABLED : 0)); - if (err) { - f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.", - type, err); - for (type--; type >= 0; type--) - dquot_quota_off(sb, type); - set_sbi_flag(F2FS_SB(sb), - SBI_QUOTA_NEED_REPAIR); - return err; - } + if (err) { + f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.", + type, err); + for (type--; type >= 0; type--) + dquot_quota_off(sb, type); + set_sbi_flag(F2FS_SB(sb), + SBI_QUOTA_NEED_REPAIR); + return err; } } return 0;