From patchwork Fri Apr 7 18:31: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: 80968 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp475852vqo; Fri, 7 Apr 2023 12:03:01 -0700 (PDT) X-Google-Smtp-Source: AKy350YiVEs4Di896MFK0wpk2eZOJSBm/gaIenX3RZP6hFHZdrBnqtAE3QDXY2kTFaVFqf4WFylM X-Received: by 2002:a05:6a20:6a82:b0:cb:8885:5650 with SMTP id bi2-20020a056a206a8200b000cb88855650mr3415902pzb.55.1680894181041; Fri, 07 Apr 2023 12:03:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1680894181; cv=pass; d=google.com; s=arc-20160816; b=jNoNG2GIseFexr2jn4ZY9NomOyUKP6m6CBHwAf0c5Iaq1UyZuZ8TiFnL0uxqKcH22Y pjb43CkTuW/r37kFc1YoB4d7eMz92APFwGntT3Jh02RTgag3jx51imkpte0jwUDPXxhn CtK4skCMNN9U53MzYkf7vQZ1Pt1bhZZCe51nyL7NePFYluMJ/xiSr98h8yH+uuuBHYRi iv6+8+OZ0tU/9WTO4PCPgc4nINULODaYXbwx0214nsoDwCUgKXo0yQ7Tq84Ogz0gUId9 xT0Pey2QUU4cjSGw1bp5GZxUb91N7KX7/B94iS+cQnECDbTY8s6zOb75ewZqFUSq79cL vRNA== 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=5R6aTbtRk9Kocpu/SZFZ0cQ64vlufYmNjZ3oQCgXYVk=; b=VMganxNvcEZdxnu1z+mZ4wPZLbh81ryx8axflk2v8Nzc7bveufb92JBXWYWLiZyrQo LehvsgtqkSgvKEs5g19smsowK+EO3xWtLc0H48kjLnSNvY8IjMSajQ2spB102oOg6gca X4vt6aqbKYX8CSZVzZxiSWkueDo1rZRy5eGLLCZoGZDK1i3+rdpNGqcch5vU8DE6SrjZ zmOrKSLE+5mlsuGiNOK00NsVRO7rNny2h7Rye57fTraeE8uk4yizr8kr80cE3XtrNN+G hFxTKUJPyiyUsIfJeY4/NbOltVylbMczzAhR5N2Fo+jzXLo95ENy8iSZJTQ4EMu91aKJ kXAg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b="g/y8brdP"; 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 i8-20020a056a00004800b0062a41fe229csi4125387pfk.267.2023.04.07.12.02.47; Fri, 07 Apr 2023 12:03:00 -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="g/y8brdP"; 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 S229482AbjDGScK (ORCPT + 99 others); Fri, 7 Apr 2023 14:32:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229737AbjDGScI (ORCPT ); Fri, 7 Apr 2023 14:32:08 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2137.outbound.protection.outlook.com [40.107.117.137]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95155A24F for ; Fri, 7 Apr 2023 11:32:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RZTDmqRTIomo6WsxhdjiGPbmmsV4xqT82tq7/vHhF0nKXNq2LC5OTtou2uRuIa62bi6Ueihf7xrY4q1MMFBUQnHaLHv/YwOAfuWjN65o9rTFsYPR1jUIJl7IMitNt32192+u0EFfNxmHFs1ZFgsaPrpQDNn1bTgqmZH/ek9ByohGDFd1QfEq2bmExsCKrzV+CBd6rJCOebJ51E9vCK+15Jmllg+IbiIRBZwUXQOKChOJTWNBCcXF+YtwE55Eig3RaK8X5kMctQfkhPXwlxwPoUI/mBsnjJaXG69VskDYwA4/FCwbjf8UxCWr709EotTgghh80aJIqrzIRgY3aifINQ== 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=5R6aTbtRk9Kocpu/SZFZ0cQ64vlufYmNjZ3oQCgXYVk=; b=YvwIiN/HpLaHlDTruqhVH82WxSchtBd05cwj3xD33zeQO5tqso5mfsKXIgpn8p5+wRbyQn+9ftHQi7UKkEVlecOYhf+MlAKvkBCmu00v6vyiar3Mk8oY7jo3ofOwKHVZEuXf4ZU+IU7qa7ATp/tgdLgvE9zGTBcYweobBS4FmNxuftHPYjbnLbNuumMkfS84K3DB7awKpDpLo2H+AFDzdBroc3Q7F/6qvdIyR4wjIs5IkZoNvSFE2N2CKy3Jz986BHK43UivLmDQrjZ8o0L6rrHfMwL1qWRrmIA/uW+FuzfsdLz4KOwP5HXOwYvrFuj67hyL4gsA0jvmx1HVWbVWgQ== 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=5R6aTbtRk9Kocpu/SZFZ0cQ64vlufYmNjZ3oQCgXYVk=; b=g/y8brdPmArhjDYXa8bDm6bTF55G6+m+9hIozASNuwjwO64Dt0UfsLXhUsQvr5B6Z9GfygN8g50vb7gAU+WiRg45E5bTYKHhLoPBIDtuSfiA/NmT671CsE/szfT6MSPLW9ohAdMk58xa5OOSfaf+l2j3rBAmzAbGHHgzrniHM3uBs+qKkaJcK8J+dFmILfdoQ5TkeIE5+7Y6glgcM8EUpSUN6ENN/HwsOfGTAkLvLy+20e1+1RKrbfKMxiZY8n9DJXcH6R/HwWJwtofSoyDmpf7FsZMmV1ZlKcUJxfpqM1fpTwFuFjWZs0zxoS+MnYNKxNgDiK3N1Y90iGJKSmu01Q== 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 TYZPR06MB5225.apcprd06.prod.outlook.com (2603:1096:400:1fa::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.31; Fri, 7 Apr 2023 18:31:58 +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.6277.031; Fri, 7 Apr 2023 18:31:58 +0000 From: Yangtao Li To: Jaegeuk Kim , Chao Yu , Nick Terrell Cc: Yangtao Li , linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v3] f2fs: add sanity compress level check for compressed file Date: Sat, 8 Apr 2023 02:31:47 +0800 Message-Id: <20230407183148.23231-1-frank.li@vivo.com> X-Mailer: git-send-email 2.35.1 X-ClientProxiedBy: SI2P153CA0030.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::15) To SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5269:EE_|TYZPR06MB5225:EE_ X-MS-Office365-Filtering-Correlation-Id: 379769f4-b8fc-47ee-ac64-08db37965ee6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6xdphdZIDGtDKoexSQwppmtc3u+dP/MzSuhsLBiMTmvEWFQMF2aGQkR4ppnKQO3gId9ZzctT/2C+CepDn70P9bbSiXveKrjG/JA6HZ3G9L4ri5aO0jeaYqw5nFQChWBMCe+adcH+rrGkpsApehddYdU1ILv2T5drl5whPmBSs0HMZmD8KAoQFOcFaL0nxbnoipBRRoOG0qYUURa5q1AjcHPyCoGEV1XkPnUv3GRkJ9le9KM3Wk3UZC+Ta+5V8utD6XluYiBi6+ER4VEil2f6zvlS7+MhN4OgL+vBHDbd5zXcnkrkjedaqQVZNph59vnYeXtCS6gPqdLf3uDnhjbq+cgYDgn6dssqyj3UCkOXwe3a3cmS3ztbKEkY0LXlZk3L1V+eU5hB16+B129M2VnFOTsD9DM+xm3x0vjxQ+kcdweCbbU+B7RdkpB2Wuqe/tZNgf01+GGnMGhc4gbc3OgwdSGCYVIFfuKagir+hAg4N8+8soGD4smWwzUMqHNybtiK0J4ThHuuMLOI5FsA+DFVmbBuiJi0K1ht5BoKyzRzRPGASUVcT9pUWWpiixUgZMz4uSS8qc5oRzNxJA9EZDMNZH82X50qAuWWOD5TApDVCxI3Zz6EarAri1lv8VDsRUAa 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)(366004)(376002)(346002)(39860400002)(396003)(136003)(451199021)(478600001)(52116002)(6512007)(1076003)(6666004)(6506007)(26005)(36756003)(41300700001)(186003)(110136005)(66556008)(4326008)(66476007)(6486002)(66946007)(316002)(86362001)(8676002)(8936002)(83380400001)(38100700002)(2616005)(38350700002)(5660300002)(2906002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RlVuF9Da+txS8lj9dukDV4WwmX4oihhIgI9VkmRogmuYTFv1zSZfekOCG4irlNU4Wzzun9moGsNl/h9KVV2QbLAVMh0UpXR6Be//Lc4JJb3ewx3MDXOkmyIbIfUzaKJzqCFJIUi02B7P8ZVt3hJTMZiqMQu0QXwJ6kDy9XzUzi6mYZdPsJCXt0qwZ5QSmzp2fYjbOHlzExE/UP7aLbcx1hsPJveDF9H2KoWf9w1ZJiMrKRPBKGegcyJAmdjDx1kc99m8QptPbpUhtCQoP4bE37YuX7DWObfOCstim6djZRXBye+thZ39+HgFjfNTe9NQaNzS89pCdZ+dX5nG8M+CSeQt8WieIpYgDkFAz19y4vRULkrDQC9x13Wd9oRAaVqVxPC+hX6eUKJNCGgwJkgYoAAcxDNVoJs577xlSYgLnJn/LyRLagT+k+b9NRmrpEHeI/rjGLnJKc8y7TflUCHToRkG4CB0r5CutieBlsTPkzwEKRZV5F8Bm2+u54WD4FqexTjYeltYI0B7FjQEBitHCSBCf8irHps31nJLKzMUROJP8XJFNN3+pq9fAWhRBe9cR1aEpi2gOhgQsQeaoH2m/ynTB6AV3MYxche7w7itCGXd7lN3XUqDieTf6BkbZ+0Q12ZCaNk1cQSeu/575D/SBltPmVasI19iD81g199mVW5vqpb5KtNjI7siW/CMoI6CoWKGaBo4PkBwTKLEJrLODEarqp65seOp4uL2WTdHu/MBO7sh+/44Ue23pBHnSkeoQ2yQvembTAb8RpYV5Kh1gXEPSG21bJEGg8wHV8nllBEO0c8IwDlLHfW47pusl+w5H3RBALmNrykJa8O846hXjf7uh4VoFMG+BQMlQPm4yESHYVG79Gw3sj+zXZUV91Lp+JzsqIBISrFLSqztJh2qSuKMrkWVrV3YEBZnzktC5sqv/Lf5OJJ7bjMX0Nu4tsU7MFkacFfuh+P+Op3/EAWtskEweFU2nX+WzVXcyhGqWGSlN3f56844mZATLjfP1qkvpb+nJ3+lBXqdSztOtcHXTSs2aigmF8eJMepvjwLmmdaJay1jP3hzimkHyXKw7aMJOXkQRe0yNgolmaKE8iM09TFfGviYSgnpigPtPVK7tGIonPSpge22YDPwOwHos+2bcqrPcVbLmkZfbnVSL6AdLhgiaDFT1EqVsNNLDSxXeKfFeaVjPm+7qBHIWfDpNPkwqiqVg80qg8RfAsqciaJFNEDJlkmDhLA6x+AHBaHTiLUAydKpQPpyFDoYL2OBbfHC7vOa8u7WYrLZmHsYfI/iBfoHNcSNEhweFm8Wo+kyb42azPyEzhaLGoukXzY66RFec30cPjr25m+OiHZ/Vt9PKyyqtXAKs53XTWc6S/OxcGY0lcH9IdAYDNotsCye/WWwb5c2m2UdQJzxfBaSToHaBchHfVmwiVYNJ9MZExRmEbrcWnib0GVHCDt/3QPzD0rhnz8e0KE5bLh6rvCBEv2YxhMTE+EZlAAmX3vBxNk5dJ7OjiPGKH+X8FLplXMTNLJngyIvcrtg1OjpPNGLtwUGwCvyCICCxyepGTxu0t7wfLUC4LWCQxW20/H2VBD3sqUt X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 379769f4-b8fc-47ee-ac64-08db37965ee6 X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB5269.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Apr 2023 18:31:58.1186 (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: WIn7KQB1yrwM+Zu6HGQCkiAUsKI7dkEJnpcFqTO0vpMVPt6YT2BTZ9E9ylcPsx3W7weX4yU5wwCJYLrRcpcONg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB5225 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?1762545296613347270?= X-GMAIL-MSGID: =?utf-8?q?1762545296613347270?= Commit 3fde13f817e2 ("f2fs: compress: support compress level") forgot to do basic compress level check, let's add it. Signed-off-by: Yangtao Li --- fs/f2fs/inode.c | 106 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 77 insertions(+), 29 deletions(-) diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index bb5b365a195d..c2460f51bf80 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,79 @@ 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) { + f2fs_warn(sbi, + "%s: inode (ino=%lx) has unsupported compress algorithm: %u, run fsck to fix", + __func__, inode->i_ino, ri->i_compress_algorithm); + goto err; + } + if (le64_to_cpu(ri->i_compr_blocks) > + SECTOR_TO_BLOCK(inode->i_blocks)) { + 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)); + goto err; + } + if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE || + ri->i_log_cluster_size > MAX_COMPRESS_LOG_SIZE) { + 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); + goto err; + } + + compress_level = le16_to_cpu(ri->i_compress_flag) >> + COMPRESS_LEVEL_OFFSET; + switch (ri->i_compress_algorithm) { + case COMPRESS_LZO: +#ifdef CONFIG_F2FS_FS_LZO + if (compress_level) + goto err_level; +#endif + break; + case COMPRESS_LZORLE: +#ifdef CONFIG_F2FS_FS_LZORLE + if (compress_level) + goto err_level; +#endif + break; + case COMPRESS_LZ4: +#ifdef CONFIG_F2FS_FS_LZ4 +#ifdef CONFIG_F2FS_FS_LZ4HC + if ((compress_level && compress_level < LZ4HC_MIN_CLEVEL) || + compress_level > LZ4HC_MAX_CLEVEL) +#else + if (compress_level) +#endif + goto err_level; +#endif + break; + case COMPRESS_ZSTD: +#ifdef CONFIG_F2FS_FS_ZSTD + if (!compress_level || compress_level > zstd_max_clevel()) + goto err_level; +#endif + break; + default: + goto err_level; + } + + return true; +err_level: + f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported compress level: %u, run fsck to fix", + __func__, inode->i_ino, compress_level); +err: + set_sbi_flag(sbi, SBI_NEED_FSCK); + 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 +361,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; }