All of lore.kernel.org
 help / color / mirror / Atom feed
From: "André Almeida" <andrealmeid@collabora.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
	Theodore Ts'o <tytso@mit.edu>,
	Andreas Dilger <adilger.kernel@dilger.ca>,
	Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <chao@kernel.org>
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" <drosen@google.com>,
	"Chao Yu" <yuchao0@huawei.com>,
	"André Almeida" <andrealmeid@collabora.com>
Subject: [PATCH 3/3] f2fs: Prevent dangling dentries on casefold directories
Date: Sun, 28 Mar 2021 11:43:56 -0300	[thread overview]
Message-ID: <20210328144356.12866-4-andrealmeid@collabora.com> (raw)
In-Reply-To: <20210328144356.12866-1-andrealmeid@collabora.com>

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 <andrealmeid@collabora.com>
---
 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


WARNING: multiple messages have this Message-ID (diff)
From: "André Almeida" <andrealmeid@collabora.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
	Theodore Ts'o <tytso@mit.edu>,
	Andreas Dilger <adilger.kernel@dilger.ca>,
	Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <chao@kernel.org>
Cc: kernel@collabora.com, "Daniel Rosenberg" <drosen@google.com>,
	linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net,
	"André Almeida" <andrealmeid@collabora.com>,
	linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org,
	krisman@collabora.com
Subject: [f2fs-dev] [PATCH 3/3] f2fs: Prevent dangling dentries on casefold directories
Date: Sun, 28 Mar 2021 11:43:56 -0300	[thread overview]
Message-ID: <20210328144356.12866-4-andrealmeid@collabora.com> (raw)
In-Reply-To: <20210328144356.12866-1-andrealmeid@collabora.com>

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 <andrealmeid@collabora.com>
---
 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



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

  parent reply	other threads:[~2021-03-28 14:45 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-28 14:43 [PATCH 0/3] fs: Fix dangling dentries on casefold directories André Almeida
2021-03-28 14:43 ` [f2fs-dev] " André Almeida
2021-03-28 14:43 ` [PATCH 1/3] fs/dcache: Add d_clear_dir_neg_dentries() André Almeida
2021-03-28 14:43   ` [f2fs-dev] " André Almeida
2021-03-28 15:07   ` Matthew Wilcox
2021-03-28 15:07     ` [f2fs-dev] " Matthew Wilcox
2021-03-28 15:49     ` André Almeida
2021-03-28 15:49       ` [f2fs-dev] " André Almeida
2021-03-28 17:39   ` Al Viro
2021-03-28 17:39     ` [f2fs-dev] " Al Viro
2021-03-30  1:48   ` Eric Biggers
2021-03-30  1:48     ` [f2fs-dev] " Eric Biggers
2021-03-30 12:54     ` André Almeida
2021-03-30 12:54       ` [f2fs-dev] " André Almeida
2021-03-28 14:43 ` [PATCH 2/3] ext4: Prevent dangling dentries on casefold directories André Almeida
2021-03-28 14:43   ` [f2fs-dev] " André Almeida
2021-03-28 14:43 ` André Almeida [this message]
2021-03-28 14:43   ` [f2fs-dev] [PATCH 3/3] f2fs: " André Almeida

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210328144356.12866-4-andrealmeid@collabora.com \
    --to=andrealmeid@collabora.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=chao@kernel.org \
    --cc=drosen@google.com \
    --cc=jaegeuk@kernel.org \
    --cc=kernel@collabora.com \
    --cc=krisman@collabora.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    --cc=yuchao0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.