From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C855C433EA for ; Sun, 28 Mar 2021 14:45:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1DCBC6196C for ; Sun, 28 Mar 2021 14:45:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231373AbhC1Oo5 (ORCPT ); Sun, 28 Mar 2021 10:44:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231321AbhC1Ooe (ORCPT ); Sun, 28 Mar 2021 10:44:34 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CBFBC061756; Sun, 28 Mar 2021 07:44:34 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id CED981F46335 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: Alexander Viro , Theodore Ts'o , Andreas Dilger , Jaegeuk Kim , Chao Yu Cc: krisman@collabora.com, kernel@collabora.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Daniel Rosenberg , Chao Yu , =?UTF-8?q?Andr=C3=A9=20Almeida?= Subject: [PATCH 3/3] f2fs: Prevent dangling dentries on casefold directories Date: Sun, 28 Mar 2021 11:43:56 -0300 Message-Id: <20210328144356.12866-4-andrealmeid@collabora.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210328144356.12866-1-andrealmeid@collabora.com> References: <20210328144356.12866-1-andrealmeid@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Before making a folder a case-insensitive one, this folder could have been used before and created some negative dentries (given that the folder needs to be empty before making it case-insensitive, all detries there are negative ones). During a new file creation, if a d_hash() collision happens and the name matches a negative dentry, the new file might have a name different than the specified by user. To prevent this from happening, remove all negative dentries in a directory before making it a case-folded one. Fixes: 2c2eb7a300cd ("f2fs: Support case-insensitive file name lookups") Signed-off-by: André Almeida --- fs/f2fs/file.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index d26ff2ae3f5e..616b7eb43795 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -1826,6 +1826,10 @@ static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask) return -EOPNOTSUPP; if (!f2fs_empty_dir(inode)) return -ENOTEMPTY; + + if (!(masked_flags & F2FS_CASEFOLD_FL) && + (iflags & F2FS_CASEFOLD_FL)) + d_clear_dir_neg_dentries(inode); } if (iflags & (F2FS_COMPR_FL | F2FS_NOCOMP_FL)) { -- 2.31.0