Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3710142rdh; Tue, 28 Nov 2023 01:25:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHR6Cx7fK/EfsuSjr2DHIkEN2R/BnfKoURpmkF4qGYbjWdokXmkJy+n0wDun6xpuSSDS7PA X-Received: by 2002:a05:6a00:854:b0:68f:ece2:ac2a with SMTP id q20-20020a056a00085400b0068fece2ac2amr15996286pfk.27.1701163538369; Tue, 28 Nov 2023 01:25:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701163538; cv=none; d=google.com; s=arc-20160816; b=yo7JoJx9aeSh3QoRWSF0X4HPZ+sRftcBzuGMx9jFDHv0JVf8OpgRssyraGFDEHMTWz e2jIohwCC9HFc2w1q9+Zwltmc2MYOEcvtyjLT50b4Blvj87ukr+XoKHe2rc5jTgPzJxG AXZ8ChhDN29u2KIFq71CYexKffYkABnuYMcXkCggUziurdczCp7uOnWYaStC7oJ22UhL EKd2MiY+Ez8fNk+QmOWDzlJio/2BJn4Sbexzrt3FANwUxq+jXrXX36ppp1ee5YfDY9c4 z1BoE+A6Ko3DYwDUU0HAlCmC9D/HFDhF3ruEXIJR0AqZv06AP2EKHZ+Oon8nEW22ZhZG NISw== 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 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id 14-20020a63000e000000b00577616e3ad9si11426712pga.871.2023.11.28.01.25.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 01:25:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; 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 23.128.96.34 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 2FF5982E7B16; Tue, 28 Nov 2023 01:25:35 -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 + 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 ); 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 ; 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 To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu , Jan Kara , Al Viro 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: 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:35 -0800 (PST) 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 --- 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