Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1188988rwb; Thu, 22 Sep 2022 11:16:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7u85b2qbfSCt79Duxqz+dfOoVbcdqxWojelI3SqwPL7JqLoVWrfwVk9wpRRukNsdA6cZ9R X-Received: by 2002:a17:902:b20a:b0:178:6f5b:f903 with SMTP id t10-20020a170902b20a00b001786f5bf903mr4674748plr.39.1663870613869; Thu, 22 Sep 2022 11:16:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663870613; cv=none; d=google.com; s=arc-20160816; b=guRFki/og9qNMl5fYX6Dt5rtd3fUQMFWl/YDvn28jotoLtQcRjqQABTHekL2cLRIGU k12UNDSYqaFsOwI9kIiv/VpLeD+6Ae/re9R0G1xGjB+vFRN7bsG+8LuSuLhkzleoP6s+ ZXahXGL0MPCbg6Oc1wdwvMytVEftPehvZ9UGCjh3JGruo7YeQTV+5GTFuHg1GhDJr3DP RaIYH+qK8Ay7FgYb4wzxON/9K+h2W9cpoTQmODRI7HyNcASLglgFAZj5syQ9uc8Z0Fpj TnuFXd2vmVgSkNI4zxkEoScwqT59YQsRkFs+fJh5k1PTXnmd+SUFCSzEodtztMF22APC Nelw== 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=L2kP0y3O811B3J1y6LUqlZ72PofpZz/Xu4zk9bziClw=; b=Y5sOzh2HPuaoNI+okJ7RyK+1yhChDkJeMaNRbaz7sR0eaqX2NXKFT17AQHohwICy+n x3CoLvzXU4YOwyaKbLdeqVSY25CjaYqfB0bGLSze/xQUOdKxwXWgxfhgfYsR2NAt5aDY s/pQLsATkN1f68VJRIfjoQkvcixqcXPHwN7Rvn/IKMN7137K8KvXyIghPt3Yq37J2lH5 55VY2c6Y+andIq3UOrqqP0VS4v2RT+gX28ZgkndyUyQmI/SO04iTmhxr3giBRUWtnDpS mjI52O7nVFqO7DL9HtD0z50qOJL3AZcsGsOzWYfaLRK9qjLtVzLQelI1Zgj2kfzZxLW6 JXzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=irPy6i+F; 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=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 b2-20020a655782000000b004394c6f7accsi6625770pgr.75.2022.09.22.11.16.42; Thu, 22 Sep 2022 11:16:53 -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=@kernel.org header.s=k20201202 header.b=irPy6i+F; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232033AbiIVSLt (ORCPT + 99 others); Thu, 22 Sep 2022 14:11:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230197AbiIVSLq (ORCPT ); Thu, 22 Sep 2022 14:11:46 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF654F685C for ; Thu, 22 Sep 2022 11:11:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 1978DCE1D9A for ; Thu, 22 Sep 2022 18:11:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44466C433D6; Thu, 22 Sep 2022 18:11:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663870302; bh=qqEhrzEMHMuwKfPqoDEHNAeIHePY6satB6tP61stR18=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=irPy6i+FAzabvCDnime1nOYTYFtzdZun9SnzHmQtZ/mfdD6MC3mYJM2dJBlLdyWXa 1inDw33YQoTM1tVBwb56FTtdUndZvXItNziESWbcVhI1uammkrfV7DuY55cAuwZPgZ pBe9yHGabn26IpnOwdCJ7DRDIwjXewlfveQVY5oRzqlIwthnBKqB9o1jv4tSTYmeMS Eg1WLnnwqFUMI406C0djMwph4w+6F22vfmKZXfh34K7A9gBvvCPmeZxs5TzBRdmoGL GpCuAV3Iu+UNd/8EDKBWlXNAU0R9vAsqVUm2W/7KjyBNzAKFYJRHkmBmej6//0xHA9 kiFTcexazCscw== Date: Thu, 22 Sep 2022 11:11:40 -0700 From: Jaegeuk Kim To: Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] f2fs: fix to detect corrupted meta ino Message-ID: References: <20220913074812.2300528-1-chao@kernel.org> <44a1eca6-568b-a752-ef01-06de489eb466@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <44a1eca6-568b-a752-ef01-06de489eb466@kernel.org> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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 I modified a bit. https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git/commit/?h=dev-test&id=a9a1592fa175baaaae43f54f175a972757c47919 Thanks, On 09/22, Chao Yu wrote: > Ping, > > On 2022/9/13 15:48, Chao Yu wrote: > > It is possible that ino of dirent or orphan inode is corrupted in a > > fuzzed image, occasionally, if corrupted ino is equal to meta ino: > > meta_ino, node_ino or compress_ino, caller of f2fs_iget() from below > > call paths will get meta inode directly, it's not allowed, let's > > add sanity check to detect such cases. > > > > case #1 > > - recover_dentry > > - __f2fs_find_entry > > - f2fs_iget_retry > > > > case #2 > > - recover_orphan_inode > > - f2fs_iget_retry > > > > Signed-off-by: Chao Yu > > --- > > v3: > > - update commit title/message > > - change logic inside f2fs_iget() rather than its caller > > fs/f2fs/inode.c | 25 ++++++++++++++++++------- > > 1 file changed, 18 insertions(+), 7 deletions(-) > > > > diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c > > index cde0a3dc80c3..1baac6056733 100644 > > --- a/fs/f2fs/inode.c > > +++ b/fs/f2fs/inode.c > > @@ -487,6 +487,12 @@ static int do_read_inode(struct inode *inode) > > return 0; > > } > > +static bool is_meta_ino(struct f2fs_sb_info *sbi, unsigned int ino) > > +{ > > + return ino == F2FS_NODE_INO(sbi) || ino == F2FS_META_INO(sbi) || > > + ino == F2FS_COMPRESS_INO(sbi); > > +} > > + > > struct inode *f2fs_iget(struct super_block *sb, unsigned long ino) > > { > > struct f2fs_sb_info *sbi = F2FS_SB(sb); > > @@ -497,17 +503,22 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino) > > if (!inode) > > return ERR_PTR(-ENOMEM); > > + if (is_meta_ino(sbi, ino)) { > > + if (!(inode->i_state & I_NEW)) { > > + f2fs_err(sbi, "detect corrupted inode no:%lu, run fsck to repair", ino); > > + set_sbi_flag(sbi, SBI_NEED_FSCK); > > + ret = -EFSCORRUPTED; > > + trace_f2fs_iget_exit(inode, ret); > > + iput(inode); > > + return ERR_PTR(ret); > > + } > > + goto make_now; > > + } > > + > > if (!(inode->i_state & I_NEW)) { > > trace_f2fs_iget(inode); > > return inode; > > } > > - if (ino == F2FS_NODE_INO(sbi) || ino == F2FS_META_INO(sbi)) > > - goto make_now; > > - > > -#ifdef CONFIG_F2FS_FS_COMPRESSION > > - if (ino == F2FS_COMPRESS_INO(sbi)) > > - goto make_now; > > -#endif > > ret = do_read_inode(inode); > > if (ret)