Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4575762rwb; Mon, 31 Jul 2023 08:54:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlFYe00DPquC79rTCjjduq2BNES6WXvMOj8iv2qGU2pVAj6ZM0gCvFF/5LP/vfRxK/wfhkPo X-Received: by 2002:a05:6a00:c86:b0:682:5a68:9846 with SMTP id a6-20020a056a000c8600b006825a689846mr12565877pfv.16.1690818870860; Mon, 31 Jul 2023 08:54:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690818870; cv=none; d=google.com; s=arc-20160816; b=PQLKzeCGzDvCborr5/PJ+Qm+ioA7EZQqz5K9EG4u9woB1vKOH3+z2HYoyc4dOoVtHf CQeeU1D+Pt38BxxfdtVeG+llliwBa8YYV/Eq1+QDx0cYiHr6uBF8NZfNgPWD/daErDQP PAHQOsNBn6SQU3mqJb7Mkn9XLZYcQs1GWLWwCnnHGwJWAIxos6Z6ddtYioY0mA3yxGcB rMakwUtFkOku10gfVVaGu4Ty5xwG9WPT5z8r94MRIGK3GCf/6UdHfGTfnTZUiE/DZ1cN SrqWoqd/aEQy5lF6Xt1NMfgs6AwFjBW2Fc3KtnhoCJBl6s/Vtjc2+x1MAZjwlrittKhY 94SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=aW0IK7mWxn9x4fSJfO5TCJT48qOczdJggGboOJahZgc=; fh=P6ouQAbbBChABBMBD7aeumI3dfc6JLm80I6nF5y+BV0=; b=g5+dp0aYzADc2C3YeY6k0lSnacIDB6GLR6z1ePbXzR/U0+6VQpWw6Zr+ioG/NcRXfM s92EL/zzgOpSByCwB2qmpmz3w21SMCv3jS8oPl/VDrZRTMTlSz6blCFDEHJ/TtUrDv6u I3rpg/qdjL/2hKsmo2kRW9sbSx+jYSl3VQ3CHuPHT9EkpMoBmH4Kg62P+ZyymzhMfFY7 1g7GgMiX49sp8Y3/3/Ph8f0s1np6sxZhq8uPbyqPEnL239SFObKNyUysdgcvZh6MuLs7 2dL3WeCi8EmdE9Mt+7bXEP6g30vexKNxm7+6BUPG0LX780rr15vEV0yMW5zFNT6gkPT4 39dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lit37bnl; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y23-20020a63de57000000b0055c8fd5fe00si7256080pgi.886.2023.07.31.08.54.14; Mon, 31 Jul 2023 08:54:30 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lit37bnl; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231831AbjGaPli (ORCPT + 99 others); Mon, 31 Jul 2023 11:41:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231510AbjGaPli (ORCPT ); Mon, 31 Jul 2023 11:41:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77980171B; Mon, 31 Jul 2023 08:41:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 17279611B3; Mon, 31 Jul 2023 15:41:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C8BAC433C9; Mon, 31 Jul 2023 15:41:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690818094; bh=pfPkl/XcTZd6RMGu2uh5vTemrvIMiriILRyHow4+KYs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lit37bnl8taUcq0x/ZnX6IWyhn/ACxWhlqLkYm57pz06QMq+FitKMIbOvp6bahXRI O9nBTwtPke2LxFZahShly7hstfWFfVQeP5zVO1HB7X4wW8lmv60svVOKl06gLSbzzU Ooyr2l96Srw8sA1eu1JJGYhiYF6/97cHMkDO4LqUZgi96rP+phJ4yJVW3Rf4MPB55/ FuvNH35z2wUjvrOjI4JTn/fHEVg6IZAUdb6gTIrEPM8hjqSKDtwnd8QhNohxUkez2b NF6GPPUbehocPDE3c0fEmEIlPzhdUlSRY1WroXgMFWkB93bQITmMxh81JiP59Xkq49 TraiyEWY+cRsA== Date: Mon, 31 Jul 2023 08:41:33 -0700 From: "Darrick J. Wong" To: zhangshida Cc: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, zhangshida@kylinos.cn Subject: Re: [PATCH v2] ext4: Fix rec_len verify error Message-ID: <20230731154133.GA11332@frogsfrogsfrogs> References: <20230731010104.1781335-1-zhangshida@kylinos.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230731010104.1781335-1-zhangshida@kylinos.cn> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Mon, Jul 31, 2023 at 09:01:04AM +0800, zhangshida wrote: > From: Shida Zhang > > With the configuration PAGE_SIZE 64k and filesystem blocksize 64k, > a problem occurred when more than 13 million files were directly created > under a directory: > > EXT4-fs error (device xx): ext4_dx_csum_set:492: inode #xxxx: comm xxxxx: dir seems corrupt? Run e2fsck -D. > EXT4-fs error (device xx): ext4_dx_csum_verify:463: inode #xxxx: comm xxxxx: dir seems corrupt? Run e2fsck -D. > EXT4-fs error (device xx): dx_probe:856: inode #xxxx: block 8188: comm xxxxx: Directory index failed checksum > > When enough files are created, the fake_dirent->reclen will be 0xffff. > it doesn't equal to the blocksize 65536, i.e. 0x10000. > > But it is not the same condition when blocksize equals to 4k. > when enough file are created, the fake_dirent->reclen will be 0x1000. > it equals to the blocksize 4k, i.e. 0x1000. > > The problem seems to be related to the limitation of the 16-bit field > when the blocksize is set to 64k. To address this, Modify the check so > as to handle it properly. urughghahrhrhr Sorry that I missed that rec_len is an encoded number, not a plain le16 integer... > Signed-off-by: Shida Zhang > --- > v1->v2: > Use a better way to check the condition, as suggested by Andreas. > > fs/ext4/namei.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c > index 0caf6c730ce3..fffed95f8531 100644 > --- a/fs/ext4/namei.c > +++ b/fs/ext4/namei.c > @@ -445,8 +445,9 @@ static struct dx_countlimit *get_dx_countlimit(struct inode *inode, > struct ext4_dir_entry *dp; > struct dx_root_info *root; > int count_offset; > + int blocksize = EXT4_BLOCK_SIZE(inode->i_sb); > > - if (le16_to_cpu(dirent->rec_len) == EXT4_BLOCK_SIZE(inode->i_sb)) > + if (ext4_rec_len_from_disk(dirent->rec_len, blocksize) == blocksize) > count_offset = 8; > else if (le16_to_cpu(dirent->rec_len) == 12) { ...but what about all the other le16_to_cpu(ext4_dir_entry{,_2}.rec_len) accesses in this file? Don't those also need to be converted to ext4_rec_len_from_disk calls? Also, Fixes: dbe89444042ab ("ext4: Calculate and verify checksums for htree nodes") --D > dp = (struct ext4_dir_entry *)(((void *)dirent) + 12); > -- > 2.27.0 >