Message ID | 20231128092516.2882629-1-chao@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3786910vqx; Tue, 28 Nov 2023 01:25:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IGh7Jv9dVkQj0141gOtUxpIA08j6jiUKg/VEkidtinKD897EDnaOHEN5A6nckl9ECbZ6aTX X-Received: by 2002:a17:90b:3b43:b0:285:a0eb:66c8 with SMTP id ot3-20020a17090b3b4300b00285a0eb66c8mr11206877pjb.1.1701163532997; Tue, 28 Nov 2023 01:25:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701163532; cv=none; d=google.com; s=arc-20160816; b=OcyNvOJXNZc+qxjSCz4ag1fRHP6enr9BjISbne36/5mpEFG/eQNGVlrPQK5q284FMe iJPFUkIQyXEDJykyvfJkP+4WisfF4rp9Ufe2MxhwRHRSyhb7+YoQ5F5pfiTzAzkLHmcG u1aEQUgvOSfewBVsSqky2mAGBQIlWVqmNAaUcJ0rs6TP2A56ep/Umx0hkoxwthURteHg MxRm4m9o5om7es6AJqz8Bt6vBoU31dJByqcPuIGbsgygMqtA0dhqOM/N/fPz9qUMxUdq cpMN5LeRdJhoVucHb4uQICjT2IgxLcuamrhHS8rtu95j/SB9fYUlmucbvmqWn4u4v9KJ +IHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=k1Rlld7fBMsgFCuTG14dU0j6lo25v1qSgNOZfv4f+XM=; fh=dXlBNxzkdDXPZM8lYr7VHZwl7OEFohvpRmKyIWjlHAs=; b=HaC/3caJHXxBt+g/nmva9UQfpu+2pxCPsXP0cdyjFkt8zkWOTiFto97+a72hU3J6ft 4kGapaU7gsjVbGb1swU1cVbZol5AJ2jWqw3cnNo1lXA0Vj3o9KoteM4hTqNum1bTsTEg 8k0Udd4rq6OxGXdgxlu70yE0YLMSrlu21nfbcT7p9Dh6tS/JSUK6kMCjSUgezLUE55EN VRaxnSXdud/F7NVXIXj5Kti6rXmpZojMTavYqXl12JVbMuBa7Svs3ZWn1JMGGuhnQ8qB KNcMV7zvjo36zgfY5tBXAqWyKQ6KG7E8mzp7PdYaM907xzNB8ZW1ibM3pgys5ne1gy3R tdjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sb2iDi1m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id bm25-20020a656e99000000b005b96a77e712si12552654pgb.17.2023.11.28.01.25.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 01:25:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sb2iDi1m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id C53BC82FA5BD; Tue, 28 Nov 2023 01:25:28 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234834AbjK1JZS (ORCPT <rfc822;toshivichauhan@gmail.com> + 99 others); Tue, 28 Nov 2023 04:25:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234775AbjK1JZR (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 28 Nov 2023 04:25:17 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0DFDDA for <linux-kernel@vger.kernel.org>; Tue, 28 Nov 2023 01:25:22 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCDD1C433C8; Tue, 28 Nov 2023 09:25:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701163522; bh=8ei0w6/cvwAZe9ao3KX6VzPIdkZ0HCfTd2duIQACX5w=; h=From:To:Cc:Subject:Date:From; b=sb2iDi1mjSU6gmZk7txGqQ+SV1xHCgEarAPTn+dDy1TfVwI4JiQMRxQlq0xfKt2Qm hzvXi78/1gl35t6SD+gnDpON8kZNOjBVlk3Up6l0sV9BkJkfz4gID+1b5gzC1iYW9I A+LNnS5Hy/odSsknkICdXFOKY2hZTmzaK8cclhwJc8G/rODKiBARZWmXela8febKiF uQ+p63GW0wyAAfR3DQVicv6HqR6Zoeiu6JhlM+6xpv7J6z15NO5VIEeE/ep/Esta3x UGIbGohjtWQi+dtfHUBM0gylYaTIIMgYWJwjdLernpAaBLLHEHQjhX2gYEPbBkJ5+G gsCXcVWledjDQ== From: Chao Yu <chao@kernel.org> To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu <chao@kernel.org>, Jan Kara <jack@suse.cz>, Al Viro <viro@zeniv.linux.org.uk> Subject: [PATCH] f2fs: fix to avoid dirent corruption Date: Tue, 28 Nov 2023 17:25:16 +0800 Message-Id: <20231128092516.2882629-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,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 howler.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 28 Nov 2023 01:25:29 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783799253099739573 X-GMAIL-MSGID: 1783799253099739573 |
Series |
f2fs: fix to avoid dirent corruption
|
|
Commit Message
Chao Yu
Nov. 28, 2023, 9:25 a.m. UTC
As Al reported in link[1]:
f2fs_rename()
...
if (old_dir != new_dir && !whiteout)
f2fs_set_link(old_inode, old_dir_entry,
old_dir_page, new_dir);
else
f2fs_put_page(old_dir_page, 0);
You want correct inumber in the ".." link. And cross-directory
rename does move the source to new parent, even if you'd been asked
to leave a whiteout in the old place.
[1] https://lore.kernel.org/all/20231017055040.GN800259@ZenIV/
With below testcase, it may cause dirent corruption, due to it missed
to call f2fs_set_link() to update ".." link to new directory.
- mkdir -p dir/foo
- renameat2 -w dir/foo bar
[ASSERT] (__chk_dots_dentries:1421) --> Bad inode number[0x4] for '..', parent parent ino is [0x3]
[FSCK] other corrupted bugs [Fail]
Fixes: 7e01e7ad746b ("f2fs: support RENAME_WHITEOUT")
Cc: Jan Kara <jack@suse.cz>
Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Chao Yu <chao@kernel.org>
---
fs/f2fs/namei.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Tue 28-11-23 17:25:16, Chao Yu wrote: > As Al reported in link[1]: > > f2fs_rename() > ... > if (old_dir != new_dir && !whiteout) > f2fs_set_link(old_inode, old_dir_entry, > old_dir_page, new_dir); > else > f2fs_put_page(old_dir_page, 0); > > You want correct inumber in the ".." link. And cross-directory > rename does move the source to new parent, even if you'd been asked > to leave a whiteout in the old place. > > [1] https://lore.kernel.org/all/20231017055040.GN800259@ZenIV/ > > With below testcase, it may cause dirent corruption, due to it missed > to call f2fs_set_link() to update ".." link to new directory. > - mkdir -p dir/foo > - renameat2 -w dir/foo bar > > [ASSERT] (__chk_dots_dentries:1421) --> Bad inode number[0x4] for '..', parent parent ino is [0x3] > [FSCK] other corrupted bugs [Fail] > > Fixes: 7e01e7ad746b ("f2fs: support RENAME_WHITEOUT") > Cc: Jan Kara <jack@suse.cz> > Reported-by: Al Viro <viro@zeniv.linux.org.uk> > Signed-off-by: Chao Yu <chao@kernel.org> Thanks for fixing this! Makes sense to me so feel free to add: Reviewed-by: Jan Kara <jack@suse.cz> Honza > --- > fs/f2fs/namei.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c > index 3b1793cfb002..ede6afb81762 100644 > --- a/fs/f2fs/namei.c > +++ b/fs/f2fs/namei.c > @@ -1105,7 +1105,7 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir, > } > > if (old_dir_entry) { > - if (old_dir != new_dir && !whiteout) > + if (old_dir != new_dir) > f2fs_set_link(old_inode, old_dir_entry, > old_dir_page, new_dir); > else > -- > 2.40.1 >
Hello: This patch was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <jaegeuk@kernel.org>: On Tue, 28 Nov 2023 17:25:16 +0800 you wrote: > As Al reported in link[1]: > > f2fs_rename() > ... > if (old_dir != new_dir && !whiteout) > f2fs_set_link(old_inode, old_dir_entry, > old_dir_page, new_dir); > else > f2fs_put_page(old_dir_page, 0); > > [...] Here is the summary with links: - [f2fs-dev] f2fs: fix to avoid dirent corruption https://git.kernel.org/jaegeuk/f2fs/c/53edb549565f You are awesome, thank you!
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index 3b1793cfb002..ede6afb81762 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c @@ -1105,7 +1105,7 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir, } if (old_dir_entry) { - if (old_dir != new_dir && !whiteout) + if (old_dir != new_dir) f2fs_set_link(old_inode, old_dir_entry, old_dir_page, new_dir); else