Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5172044iob; Mon, 9 May 2022 10:07:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuaw/y9ysqjSqvWuXguURsSh3wuP3aix6rfFJd0AgC1XV+cd9FpqX3ZX56ui8bm3nAaRrw X-Received: by 2002:a05:6808:ecf:b0:2f9:f0b1:7ee8 with SMTP id q15-20020a0568080ecf00b002f9f0b17ee8mr7855608oiv.225.1652116027597; Mon, 09 May 2022 10:07:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652116027; cv=none; d=google.com; s=arc-20160816; b=cSvpPNccM7+QUft6mCVwPAg/V7veVjJP7UXsnfhwGHYsT2oDm3DbmgeSCI6dmhR8AS WlqfnFr6CWsSgxKNhKPbUiU28vG7o0Cs3+E2DyvfYeThN2OozWfEKSWBHw5Rwt/8f4Jg WxazE3Fic/VU5ZIVYlDnrTBWp7mGcArygnSNvQ/wqNqg19y4zVCm/7fFB5MKIQiusmUd TRr8o2u6uAoWx2NXqjeZowjZJsGq2kHnD9zogTGyOZzh4hyKMhlEYRgFdOVYSQNg8MXr Pi9+oDLlIHMgkpbpZUBK1Gz64/rvDOGL9wefTjEuT+xD0dptiffto4KJhJdl5mw+wDG/ mS5Q== 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=MkJQ6qBf4iIPY4C4mrIVAlhnbR5nRduVdUJhWsd24BY=; b=MJZ4y/01irPsh6NYPfTGPpG767BMy3doqPwiyVaYVo3kdniP3Jhcg58tgsuRhNNCGc pvdxOyoSR5zuZTjD2fgEFVfOqbU6JWNlv+ZFKlUYo7+EJIuzZFBxf7C9TDiFVF58nYRB EKkCMHQv2IxyeWYm+Qqr9vw1zpQTvYK+DnxFWTAUnbMHwYDeGx/QbIVm0y4flDbB0zsi yb/bZEyOTqfL3+H/vVomnYEwWxU8y/ZeAPAkXCV4lF/Gpnu0KZ6CfJx8197zw/sa4O9q Yg/+9l8S9WZrssxqPSMnWIrxM2OX3+FR6SUvqp8wwVMYNv7JWpiDSX8HpcHGa3OrV0YO zgUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RJuMf1pa; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id c20-20020aca1c14000000b002f98f884aa0si10065316oic.32.2022.05.09.10.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 10:07:07 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RJuMf1pa; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6A58C1E38B9; Mon, 9 May 2022 09:58:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239443AbiEIRBb (ORCPT + 99 others); Mon, 9 May 2022 13:01:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239336AbiEIRB2 (ORCPT ); Mon, 9 May 2022 13:01:28 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12F811E05AE; Mon, 9 May 2022 09:57:32 -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 ams.source.kernel.org (Postfix) with ESMTPS id 19EA1B81810; Mon, 9 May 2022 16:57:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95B52C385B2; Mon, 9 May 2022 16:57:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652115449; bh=OaXybH4jCWXEKkCxz9xjsRa7BIfvoYHVfNPxqyV5/94=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RJuMf1panOt4mw/iicfCpg3O5q1+LpvR5dgUX36eHh6ymw2J8oEJm/XBJWo4zWYMg 65WG208cr1xfLdqpe9wBhyt42K8i5l2tm8+i8sLFmIZDrhO+tbV7X5lfCrlX7ircJl +R00oiq9K+1s7SjB0TKqXkgDjsnSFrt0F+fbP+256Wfk5EUjJjytQDMVWKKNcuxuzX mYmCJXdAn9zeS7QTGq6BPC3UyEqJWO/0Md+QNIdj1yqpQ2eqLiHkfnmCbMb372dmzD +bsJ9ZmNjacbiPN8njZICA9SOhg18ljW0Pk4jBLraIazA+9VXCDxdX1unB/mAPLYQa qD9N9Tl9+FzQA== Date: Mon, 9 May 2022 09:57:27 -0700 From: Jaegeuk Kim To: Chao Yu Cc: Ming Yan , linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [f2fs-dev] [PATCH] f2fs: fix to do sanity check for inline inode Message-ID: References: <20220428024940.12102-1-chao@kernel.org> <173c51c2-eff3-8d76-7041-e9c58024a97e@kernel.org> <142acf95-c940-8d4a-7f00-08f1bb816c49@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 On 05/08, Chao Yu wrote: > Ping, This is in my TODO list, but will take some time. Sorry. > > On 2022/5/5 22:33, Chao Yu wrote: > > On 2022/5/5 11:31, Jaegeuk Kim wrote: > > > On 05/05, Chao Yu wrote: > > > > On 2022/5/5 5:28, Jaegeuk Kim wrote: > > > > > On 04/28, Chao Yu wrote: > > > > > > As Yanming reported in bugzilla: > > > > > > > > > > > > https://bugzilla.kernel.org/show_bug.cgi?id=215895 > > > > > > > > > > > > I have encountered a bug in F2FS file system in kernel v5.17. > > > > > > > > > > > > The kernel message is shown below: > > > > > > > > > > > > kernel BUG at fs/inode.c:611! > > > > > > Call Trace: > > > > > > evict+0x282/0x4e0 > > > > > > __dentry_kill+0x2b2/0x4d0 > > > > > > dput+0x2dd/0x720 > > > > > > do_renameat2+0x596/0x970 > > > > > > __x64_sys_rename+0x78/0x90 > > > > > > do_syscall_64+0x3b/0x90 > > > > > > > > > > > > The root cause is: fuzzed inode has both inline_data flag and encrypted > > > > > > flag, so after it was deleted by rename(), during f2fs_evict_inode(), > > > > > > it will cause inline data conversion due to flags confilction, then > > > > > > page cache will be polluted and trigger panic in clear_inode(). > > > > > > > > > > > > This patch tries to fix the issue by do more sanity checks for inline > > > > > > data inode in sanity_check_inode(). > > > > > > > > > > > > Cc: stable@vger.kernel.org > > > > > > Reported-by: Ming Yan > > > > > > Signed-off-by: Chao Yu > > > > > > --- > > > > > > fs/f2fs/f2fs.h | 7 +++++++ > > > > > > fs/f2fs/inode.c | 3 +-- > > > > > > 2 files changed, 8 insertions(+), 2 deletions(-) > > > > > > > > > > > > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > > > > > > index 27aa93caec06..64c511b498cc 100644 > > > > > > --- a/fs/f2fs/f2fs.h > > > > > > +++ b/fs/f2fs/f2fs.h > > > > > > @@ -4173,6 +4173,13 @@ static inline void f2fs_set_encrypted_inode(struct inode *inode) > > > > > > */ > > > > > > static inline bool f2fs_post_read_required(struct inode *inode) > > > > > > { > > > > > > + /* > > > > > > + * used by sanity_check_inode(), when disk layout fields has not > > > > > > + * been synchronized to inmem fields. > > > > > > + */ > > > > > > + if (file_is_encrypt(inode) || file_is_verity(inode) || > > > > > > + F2FS_I(inode)->i_flags & F2FS_COMPR_FL) > > > > > > + return true; > > > > > > return f2fs_encrypted_file(inode) || fsverity_active(inode) || > > > > > > f2fs_compressed_file(inode); > > > > > > } > > > > > > diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c > > > > > > index 83639238a1fe..234b8ed02644 100644 > > > > > > --- a/fs/f2fs/inode.c > > > > > > +++ b/fs/f2fs/inode.c > > > > > > @@ -276,8 +276,7 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page) > > > > > > } > > > > > > } > > > > > > - if (f2fs_has_inline_data(inode) && > > > > > > - (!S_ISREG(inode->i_mode) && !S_ISLNK(inode->i_mode))) { > > > > > > + if (f2fs_has_inline_data(inode) && !f2fs_may_inline_data(inode)) { > > > > > > > > > > It seems f2fs_may_inline_data() is breaking the atomic write case. Please fix. > > > > > > > > sanity_check_inode() change only affect f2fs_iget(), during inode initialization, > > > > file should not be set as atomic one, right? > > > > > > > > I didn't see any failure during 'f2fs_io write atomic_write' testcase... could you > > > > please provide me detail of the testcase? > > > > > > I just applied this into my device and was getting lots of the below error > > > messages resulting in open failures of database files. > > > > Could you please help to apply below patch and dump the log? > > > > From: Chao Yu > > Subject: [PATCH] f2fs: fix to do sanity check for inline inode > > > > Signed-off-by: Chao Yu > > --- > > fs/f2fs/f2fs.h | 7 +++++++ > > fs/f2fs/inode.c | 11 +++++++---- > > 2 files changed, 14 insertions(+), 4 deletions(-) > > > > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > > index 0f8c426aed50..13a9212d6cb6 100644 > > --- a/fs/f2fs/f2fs.h > > +++ b/fs/f2fs/f2fs.h > > @@ -4159,6 +4159,13 @@ static inline void f2fs_set_encrypted_inode(struct inode *inode) > > */ > > static inline bool f2fs_post_read_required(struct inode *inode) > > { > > + /* > > + * used by sanity_check_inode(), when disk layout fields has not > > + * been synchronized to inmem fields. > > + */ > > + if (file_is_encrypt(inode) || file_is_verity(inode) || > > + F2FS_I(inode)->i_flags & F2FS_COMPR_FL) > > + return true; > > return f2fs_encrypted_file(inode) || fsverity_active(inode) || > > f2fs_compressed_file(inode); > > } > > diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c > > index 02630c17da93..a98614a24ad0 100644 > > --- a/fs/f2fs/inode.c > > +++ b/fs/f2fs/inode.c > > @@ -276,11 +276,14 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page) > > } > > } > > > > - if (f2fs_has_inline_data(inode) && > > - (!S_ISREG(inode->i_mode) && !S_ISLNK(inode->i_mode))) { > > + if (f2fs_has_inline_data(inode) && !f2fs_may_inline_data(inode)) { > > set_sbi_flag(sbi, SBI_NEED_FSCK); > > - f2fs_warn(sbi, "%s: inode (ino=%lx, mode=%u) should not have inline_data, run fsck to fix", > > - __func__, inode->i_ino, inode->i_mode); > > + f2fs_warn(sbi, "%s: inode (ino=%lx, mode=%u) reason(%d, %llu, %ld, %d, %d, %lu) should not have inline_data, run fsck to fix", > > + __func__, inode->i_ino, inode->i_mode, > > + f2fs_is_atomic_file(inode), > > + i_size_read(inode), MAX_INLINE_DATA(inode), > > + file_is_encrypt(inode), file_is_verity(inode), > > + F2FS_I(inode)->i_flags & F2FS_COMPR_FL); > > return false; > > } > >