From patchwork Tue Apr 4 03:48:47 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: 78844 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2755658vqo; Mon, 3 Apr 2023 20:58:11 -0700 (PDT) X-Google-Smtp-Source: AKy350Zwk31OyT/jKmR3FSlbU9u/SXWEJCZQ+oW9mzDmbCfkxObp9JDFCWb2D9QsgktNTTom2hXk X-Received: by 2002:a05:6a20:bc9a:b0:d6:80a4:f0b6 with SMTP id fx26-20020a056a20bc9a00b000d680a4f0b6mr1046317pzb.6.1680580691418; Mon, 03 Apr 2023 20:58:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1680580691; cv=pass; d=google.com; s=arc-20160816; b=Cbjz3SfjpETfu86k8GQDDGYnIUhQNF7SkBGyrB87VagB0Zp+7etqoXlh8B/N1f/N+d OMSl15vy/k8toF2Rc381+YVERV7yskVwQr9YxN0d6bno8iGNdJbZe92/zP3zJb+G9cM9 Ka+nYtUfgMKP7BU35mJbvGtREqul3BmzFo+Tqu5nEHOZ+SE76tQVZyzTQRtbQv1RqsLB zdva9ccVDZjt7bnxuiMGDNpxYnOg9K54RQuxtD3UGEabRnAqY88mYgtKNq9TtBwIOR1u VYnU+hgXt431fEqZeX9t67UO8Uy9lVdxQwI9i5bSlknKX78nUC98DR0MU8iadtulwx1C F3ng== 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=VGTyht8d4piCA3uU7IMLkGaOcewaX1OcfUAdWZNPagE=; b=lh+5k2Ibu+Q85sj54BgTM45txYfb5pRsGvLgdbIiyYdAKmnPmSxbyDaz8DCEI8gnAG WztCrP/GTCEq4Qo2Kaq1BW+ixbWfP/ZEr10ILn+PAoFO7wMAqH6yvcZBKldHyrmyBRXk KFhy0gwlt4pUxEThV8hxvBU9muZ153Gh36QjsTpF0uHslQEYpZMyYvMy3dyknuphNhym 4WzF+LnfEfjGdDcPHe3Q289WCFLAtRklTBWL423fwCck4wt+DhDBARpoQeZFHmY/zcf8 y4ClRFNwk2I5FG15VJ4K/g3N7js0T5fpCO5lnvYVGTU70rkp0mBdk1LbDSaGS0zuXPAQ Jhfw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=p2X7lPaq; 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 z20-20020a63d014000000b005139547be00si8808345pgf.877.2023.04.03.20.57.59; Mon, 03 Apr 2023 20:58:11 -0700 (PDT) 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=p2X7lPaq; 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 S233072AbjDDDtG (ORCPT + 99 others); Mon, 3 Apr 2023 23:49:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbjDDDtE (ORCPT ); Mon, 3 Apr 2023 23:49:04 -0400 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2111.outbound.protection.outlook.com [40.107.255.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 291A11BFB for ; Mon, 3 Apr 2023 20:49:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UXCi/8eiRrBXFAJBUiMpahcrbPPEFmmflcLZAwhuni3WTsGncIC9bGIUtii85cmVS9HNkacNDFTPr5OgdhnPQ9O09lMdMa0IU3YcCArylH/WX+91pbn92xKrp9AVskEv7WMbMrEiwp8ZDT13ZgRPcW/ayEDD1g3pVwZlCX3knyFYKq6neWe8Ssna+0OBdVWYdbDv8/PJUU8LvjotTnY20NPuEqgb83+7fnk8k2fjyIVz/PQh7mJ2SAhitCZgkpcEfnmE/pSynTdNUza5W0L/JecV1iqcxH47uw8iFOk05xHR0QnzXhBtwm0QHZEr+n0fVVlPTU3SQo/dqtafruCYYw== 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=VGTyht8d4piCA3uU7IMLkGaOcewaX1OcfUAdWZNPagE=; b=cmTo5sjTS8L12NlBgaIHBFkiIV6GApYkhHv2T/OK+WA/b8bg4fRfgiZnI/CaevYKvo9TDir+Drj0rXWpS9cagkAblEZafZVCFH/JTJgf5xCduJpbNHHPgoP3FECjLS9c3qr52UYy1aQh9lmQClfgefgDwDKUgF1O52UyoQf3MkpZue9fH98cElOHjXKApwV+Czj+lbnci/lQ4g2iUf9jxRYGajm9Ky8vG0z1nGwsSuqLV4SQc8vOK4DpbS+9xgdZexZBNCwL7DukYmB2iojuGT9FTUOHx+mVMWJIyMKR/zaNHM4iPmvZ06LLqdLlpId2R/XQhFNVa1v9HAJSqxY6oQ== 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=VGTyht8d4piCA3uU7IMLkGaOcewaX1OcfUAdWZNPagE=; b=p2X7lPaqyq2VeS7yaysBPxCp8m/gNnTZv5+WUoagSI9Mz5O7ZnudYzqHGZD0YKm13y7XEAwiDk1OfhM+3CgufClaseJhl4BHqflzUvZf+cu2lx9fdb8iXQMwDjxmTsxLzoIMho4aVX5p/X95U/he3lJhLZ+yuZ3w3RmGsyRTQ+3JvI5YqRcC2yc3ROaSKmoyi6TopAzCNNbroH7jj4m1UsMJMgbs4/iBO7T4yj0OCL173Nc/gjD2LdBjtyIxOR2e/cQgRKeylsl50D7gkiBcefVUs771wH37YpRh6LMHS22tyaSBrn65cPKAxNtq6gBk04JtOA8NincStQy89+D9WA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) by PSAPR06MB4038.apcprd06.prod.outlook.com (2603:1096:301:2a::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.34; Tue, 4 Apr 2023 03:48:57 +0000 Received: from SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::a3a1:af8e:be1e:437c]) by SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::a3a1:af8e:be1e:437c%6]) with mapi id 15.20.6254.028; Tue, 4 Apr 2023 03:48:57 +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 v2] f2fs: add sanity compress level check for compressed file Date: Tue, 4 Apr 2023 11:48:47 +0800 Message-Id: <20230404034847.26667-1-frank.li@vivo.com> X-Mailer: git-send-email 2.35.1 X-ClientProxiedBy: TYAPR01CA0020.jpnprd01.prod.outlook.com (2603:1096:404::32) To SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5269:EE_|PSAPR06MB4038:EE_ X-MS-Office365-Filtering-Correlation-Id: d153d160-601b-4e62-0fdc-08db34bf84c8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /xDaiij+wAg39YibZJpj8i5p3jrQNIARJmpQRTN46LAwOy/mZEOxYa+/iPSQfUvxJ+5/4EcA1jbg5XcZGQoSek8UmPzm1X31O4LSLiJu9L+Yeauo3jkcrad+TzEKf3bfLq7fLgUfRkcqyagYc86uL+Dmztb0rohorvTKEAXE1tOyxL1vd/+NgUTjwCD6yUtVjwl817mnCSQle4I8NiRs2VldJ5W3JnIwoaba8pVyDjvajxXp77Wyd8slpWPWAOIBGqcMuMK/Yl31xquS9qPbYWvN0ICzhTeSWLuWBNNeMAAZ5nBTegefk0OXAF/A7UDYSDzl3i5L/lcVVSZBlM7AOdfU3LVvfZ8OMy2bBeRdmdHM6EiZab4vsZJLb0sK8jQM0kvgGqSKxuG04+4hyXMV03iCHz/LKWRC6I7C81Hokiq6qgrnZKqFeUfU5ak5z/wkSGvqrllsdzQSf/ryA16EWK01URYVHBaqU77rElRs2VtqVDjM+x7zQMsm/2j062CV5ltUClRVtmGGr9SK9sWI4aDgBR622EUGujmdLu5MZZAuJ/IyrsFikG4+h6SEaoflZs+4p19A/eAvHCnbn3hA+E3QfSzS5biZcH7BSWtFPsBtlH+FOkPuEqra9x//oM+u X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SEZPR06MB5269.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(346002)(366004)(39860400002)(376002)(136003)(451199021)(83380400001)(5660300002)(8676002)(38350700002)(66476007)(2906002)(66946007)(66556008)(38100700002)(6486002)(41300700001)(4326008)(316002)(2616005)(8936002)(86362001)(478600001)(107886003)(6666004)(6512007)(1076003)(26005)(6506007)(36756003)(186003)(52116002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: P6lnQViyE4V5RqgmWwRnoIkUXO4ezACDOXVb/ANrJIcaP2jjtakVm5Z9nFvMaE6sUxIjRRH/BPowmaLApxFo1f6paehbYkZt0P2NV8oEpZfuND9Wl75RTX64iaUVXidWvKbRiRFZfZGqINbm12ovyCLxj/x4GmkWh2pzXlMvYidvG1uzmgRbqv+j4HqusGJ6Louhval3TzZTBxlTJQ4rzZji+I3TjghT0kLMXAXAN6Cdu0QxmDVIWaRhF7aIWmFX1bCDB8Juggv0V6wC+bxBhgdLwQ4Escx+ysV71AzBTh3zjPKK1FMh32bs2L1HIYF+i4XhZRK2RXOsN6IxJb9Ch3Sb4tEf0Jn0uTw+ETlAN9w0IC1qAL/uCQfk15sd61Slw1Q/IDJQ/ZF6p73ficyJ2y/wU3C2G9Gsq1MViZFzYxqUldSumXlVjxmFKfjtku1JbYiy+uzX7xMATQ1RDWVFfKajbKqgkFDxjSvXobkvY/3FBZmR3gzNUTHeRZCFw61QsfCCgwMyFry/ZWI5eD76zXNaAUhOp7lNL+VEopaf/HFCHOQ+wecM0oWsHKFHOv12l3mi+VfICScEsNa0tL4MTnIjg3II2YbErII5K1nKy3WtMq1JuOA/WC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PR06MB5269.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2023 03:48:57.5980 (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: GmSAMxSjtqHiOGgQ2xcFrzgkjFWbx71oy/Ux/3s2ol5NQUVxsfPGlmKPHjtn8mcvHxvK+fpkqsdrAp6Esymf9g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PSAPR06MB4038 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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?1762216578648546539?= X-GMAIL-MSGID: =?utf-8?q?1762216578648546539?= Commit 3fde13f817e2 ("f2fs: compress: support compress level") forgot to do basic compress level check, let's add it. Signed-off-by: Yangtao Li --- v2: -convert to zstd_max_clevel() fs/f2fs/inode.c | 96 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 29 deletions(-) diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index bb5b365a195d..e6f45a7a079d 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include "f2fs.h" #include "node.h" @@ -202,6 +204,69 @@ void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page) ri->i_inode_checksum = cpu_to_le32(f2fs_inode_chksum(sbi, page)); } +static bool sanity_check_compress_inode(struct inode *inode, + struct f2fs_inode *ri) +{ + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); + unsigned char compress_level; + + if (ri->i_compress_algorithm >= COMPRESS_MAX) { + set_sbi_flag(sbi, SBI_NEED_FSCK); + f2fs_warn(sbi, + "%s: inode (ino=%lx) has unsupported compress algorithm: %u, run fsck to fix", + __func__, inode->i_ino, ri->i_compress_algorithm); + return false; + } + if (le64_to_cpu(ri->i_compr_blocks) > + SECTOR_TO_BLOCK(inode->i_blocks)) { + set_sbi_flag(sbi, SBI_NEED_FSCK); + f2fs_warn(sbi, + "%s: inode (ino=%lx) has inconsistent i_compr_blocks:%llu, i_blocks:%llu, run fsck to fix", + __func__, inode->i_ino, le64_to_cpu(ri->i_compr_blocks), + SECTOR_TO_BLOCK(inode->i_blocks)); + return false; + } + if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE || + ri->i_log_cluster_size > MAX_COMPRESS_LOG_SIZE) { + set_sbi_flag(sbi, SBI_NEED_FSCK); + f2fs_warn(sbi, + "%s: inode (ino=%lx) has unsupported log cluster size: %u, run fsck to fix", + __func__, inode->i_ino, ri->i_log_cluster_size); + return false; + } + + compress_level = le16_to_cpu(ri->i_compress_flag) >> + COMPRESS_LEVEL_OFFSET; + switch (ri->i_compress_algorithm) { + case COMPRESS_LZO: + case COMPRESS_LZORLE: + if (compress_level) + goto err; + break; + case COMPRESS_LZ4: + if ((compress_level && compress_level < LZ4HC_MIN_CLEVEL) || + compress_level > LZ4HC_MAX_CLEVEL) + goto err; + break; + case COMPRESS_ZSTD: +#ifdef CONFIG_F2FS_FS_ZSTD + if (!compress_level || compress_level > zstd_max_clevel()) + goto err; +#endif + break; + default: + goto err; + } + + return true; + +err: + set_sbi_flag(sbi, SBI_NEED_FSCK); + f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported compress level: %u, run fsck to fix", + __func__, inode->i_ino, compress_level); + return false; +} + static bool sanity_check_inode(struct inode *inode, struct page *node_page) { struct f2fs_sb_info *sbi = F2FS_I_SB(inode); @@ -286,35 +351,8 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page) if (f2fs_has_extra_attr(inode) && f2fs_sb_has_compression(sbi) && fi->i_flags & F2FS_COMPR_FL && F2FS_FITS_IN_INODE(ri, fi->i_extra_isize, - i_log_cluster_size)) { - if (ri->i_compress_algorithm >= COMPRESS_MAX) { - set_sbi_flag(sbi, SBI_NEED_FSCK); - f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported " - "compress algorithm: %u, run fsck to fix", - __func__, inode->i_ino, - ri->i_compress_algorithm); - return false; - } - if (le64_to_cpu(ri->i_compr_blocks) > - SECTOR_TO_BLOCK(inode->i_blocks)) { - set_sbi_flag(sbi, SBI_NEED_FSCK); - f2fs_warn(sbi, "%s: inode (ino=%lx) has inconsistent " - "i_compr_blocks:%llu, i_blocks:%llu, run fsck to fix", - __func__, inode->i_ino, - le64_to_cpu(ri->i_compr_blocks), - SECTOR_TO_BLOCK(inode->i_blocks)); - return false; - } - if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE || - ri->i_log_cluster_size > MAX_COMPRESS_LOG_SIZE) { - set_sbi_flag(sbi, SBI_NEED_FSCK); - f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported " - "log cluster size: %u, run fsck to fix", - __func__, inode->i_ino, - ri->i_log_cluster_size); - return false; - } - } + i_log_cluster_size)) + return sanity_check_compress_inode(inode, ri); return true; }