Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2978625pxf; Sun, 28 Mar 2021 07:49:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKlAa+G6QNHzPMtqg7xfSYOLcIMoa471KfpeCSr+BB1DMCB1Yl9aXmx4CTZwAIbvmdCtHI X-Received: by 2002:a17:906:4410:: with SMTP id x16mr24607066ejo.446.1616942953162; Sun, 28 Mar 2021 07:49:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616942953; cv=none; d=google.com; s=arc-20160816; b=o7yxElJ1M9ccCDAB3nGQ2AJN/C1MtrfFDet+sythA9+xfhjsT85zlQdPHDS/9okrYt p7LTBYXc3wN/+gzmj5h1rLTTunpSPWJ7LJnKz/Fym6enBjphbUdr/TnbYwrwLkFkdnR9 CI2Y4TLXpb1SwNFufv1ov7b/Gv+11SMO0TIFKXw+/Uq4AwTmYLKwjaXs0iBztaHwYFlx 6TUXxReCrawlMFAtQnyorSr29S6lZxv0jg0qrYbnnIEIOhndCfyFOTmQDYsirvp2ujTH uq5VO4BK+ZZKbkHhZaYs/bH5kUPurJZo+hJ1FA7TwMZ3ORWWvOi6Ks2wJUwtFjLRFsXz bQMw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=3tmB62i5iiIF22wI8qmKd1VA1vc17hYDqPD0D9ufknA=; b=xSohNuHdVYSQQHeGF5OguE4WTEoJoVqBivasw6QfQCsasNDQ/ZTJpJEl56rkKw+whC Y9N/sncoODmDlsK49UBUNyi3S19M1uXTmONVEFN7sU6aQCoGWgxTDbwPKSd8qKZymctF k85rA2wznSEGMscHMAL0n+S8IH0GSHrT/pvEo4WmSs0Qz42QkEc3yuydWmvVrYXxnLrF hfj1cz1g0d60gVIZUXV8oWY5uc35pA+9t0O3Lgm6FLjoyeGdLzOHQ8ovnKtYviopzqsX TDceP9PNdbTvmcoV8viHds/D/MsGNY+NQAqNk7otHCNiANU5/IbHRbeMpidMedUXCzFZ /cVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b14si10613644eju.424.2021.03.28.07.48.50; Sun, 28 Mar 2021 07:49:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231365AbhC1Oo4 (ORCPT + 99 others); Sun, 28 Mar 2021 10:44:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231208AbhC1Ooa (ORCPT ); Sun, 28 Mar 2021 10:44:30 -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 6E58AC061756; Sun, 28 Mar 2021 07:44:30 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id CF00F1F42CD7 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 2/3] ext4: Prevent dangling dentries on casefold directories Date: Sun, 28 Mar 2021 11:43:55 -0300 Message-Id: <20210328144356.12866-3-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: b886ee3e778e ("ext4: Support case-insensitive file name lookups") Signed-off-by: André Almeida --- fs/ext4/ioctl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c index a2cf35066f46..0eede4c93c22 100644 --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -381,6 +381,9 @@ static int ext4_ioctl_setflags(struct inode *inode, err = -ENOTEMPTY; goto flags_out; } + + if (!(oldflags & EXT4_CASEFOLD_FL) && (flags & EXT4_CASEFOLD_FL)) + d_clear_dir_neg_dentries(inode); } /* -- 2.31.0