From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C95E185B; Tue, 23 Jan 2024 00:24:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705969477; cv=none; b=EdhddFzraLBEYYwD4/w7iDp2qBJvUAtr9Z7K4uerC+RdTSAZILhOWWmoTTAJA3HOorKOIYX8jybKZt0v+CcGZZKkdrUFbXSICKsH8uMiTbvAGQ2hTQlfWSEUmSnUBHFyegh/cu/NbTZxr3gnx0UjkjaEXWPXWah2mnS8vQHOtfw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705969477; c=relaxed/simple; bh=M+PHo5stwb56/miUnGhkC0WoXmzP8SW7RbsGvjRAufA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g8cZCmTcti2/OR7YvT6TL9pGMLEWF8ScfCYWiILFz6nwtXIubeW3W/nl8/a0ybMrrorRD9UirVU3pNIrbYMZOL7rlhvARsh0iZwqFS+RdYA029fhuWUsOfTb9WmXVRJe1sqR+lxRtPI4OHOHVmu1T79Gs7FHRsq+O8OqQiz8oEM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=HuLcKLoW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="HuLcKLoW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47BF2C433F1; Tue, 23 Jan 2024 00:24:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1705969477; bh=M+PHo5stwb56/miUnGhkC0WoXmzP8SW7RbsGvjRAufA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HuLcKLoWjZaimToq/IlOTxYpX/kTFq1AGnusx27dYq4GDokhPhsgA2MDq2cIIiqze t3WtBQxkGP6V9cFDMbJ/TUqgmeknd/mrx4HWCQP76N/reiA/WbYmFi6Pb93zpnZGcL D/4BYnlt9v5fPGMYmWUFBUv8P5/mdTUBzStfnGxI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jan Kara , Al Viro , Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 6.7 263/641] f2fs: fix to avoid dirent corruption Date: Mon, 22 Jan 2024 15:52:47 -0800 Message-ID: <20240122235826.162045667@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122235818.091081209@linuxfoundation.org> References: <20240122235818.091081209@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.7-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chao Yu [ Upstream commit 53edb549565f55ccd0bdf43be3d66ce4c2d48b28 ] 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 Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- 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 d0053b0284d8..7f71bae2c83b 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c @@ -1106,7 +1106,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.43.0