From patchwork Tue Nov 28 09:25:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13470701 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DB073C4167B for ; Tue, 28 Nov 2023 09:25:34 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1r7uLV-0002b3-7B; Tue, 28 Nov 2023 09:25:33 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1r7uLQ-0002Zx-FL for linux-f2fs-devel@lists.sourceforge.net; Tue, 28 Nov 2023 09:25:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=k1Rlld7fBMsgFCuTG14dU0j6lo25v1qSgNOZfv4f+XM=; b=FM2y9AUKAWhedNLy0Q24XlhKl9 kKOS1f9xukxpCGKb3pLwF87xftS9jrO/tQEqpwSyQ+iWP5k+mu7jP1xgX00JqFPCRX/TygDOyarLV OD0LcFR24GVWR7Vx6qglxljoDNZV++vnuS4wRdn2gGlLmsFiTDr5SHCIWZASrmDUyTlQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=k1Rlld7fBMsgFCuTG14dU0j6lo25v1qSgNOZfv4f+XM=; b=D fP9xgdJrY+PyynHjhX78Oq2ATrp8Gd0/1DXTKwjdmsS8CUzPWg/OJCBenmDoZA8x6g1q59uPZTfyK ud82qAHTB44BQXmPpF7AuC4lWrPMXc/QzzVYn8TKKObhZP9/pjZKWrNZCc6RewheUrud2ItueheHB cuYZ7RDI7mtDyS4U=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1r7uLQ-0000cn-8Q for linux-f2fs-devel@lists.sourceforge.net; Tue, 28 Nov 2023 09:25:28 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D02B76164B; Tue, 28 Nov 2023 09:25:22 +0000 (UTC) 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 To: jaegeuk@kernel.org 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 X-Headers-End: 1r7uLQ-0000cn-8Q Subject: [f2fs-dev] [PATCH] f2fs: fix to avoid dirent corruption X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kara , linux-kernel@vger.kernel.org, Al Viro , linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net 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 Reported-by: Al Viro Signed-off-by: Chao Yu Reviewed-by: Jan Kara --- 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