Linux filesystem development
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <krisman@suse.de>
To: Sarthak Kukreti via Linux-f2fs-devel
	<linux-f2fs-devel@lists.sourceforge.net>,
	Theodore Ts'o <tytso@mit.edu>, Jaegeuk Kim <jaegeuk@kernel.org>,
	Chao Yu <chao@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>
Cc: Sarthak Kukreti <sarthakkukreti@google.com>,
	linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net,
	Eric Biggers <ebiggers@kernel.org>,
	linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org,
	Dmitry Torokhov <dtor@google.com>
Subject: Re: [f2fs-dev] [PATCH v2 2/3] ext4: reject casefolded names that fold to ".", "..", or empty
Date: Tue, 24 Nov 2026 14:48:56 -0500	[thread overview]
Message-ID: <87mrqyc8nr.fsf@cartola> (raw)
In-Reply-To: <20261119214944.1480596-3-sarthakkukreti@google.com>

Sarthak Kukreti via Linux-f2fs-devel
<linux-f2fs-devel@lists.sourceforge.net> writes:

> Filenames consisting solely of ignorable Unicode characters fold to
> empty strings (causing the first such file to be created on disk and
> subsequent distinct ignorable-only names to collide with it), while
> names with leading dots and ignorable characters fold to "." or "..",
> colliding with on-disk "." and ".." entries and triggering
> EXT4_ERROR_INODE in ext4_lookup().
>
> Skip casefolding when the lookup name is literally "." or "..", reject
> any non-dot names that fold to "", ".", or ".." in
> ext4_fname_setup_ci_filename(), and fall back to opaque byte hashing in
> ext4fs_dirhash() when utf8_casefold() yields "", ".", or "..".
>
> Fixes: b886ee3e778e ("ext4: Support case-insensitive file name lookups")
> Co-developed-by: Dmitry Torokhov <dtor@google.com>
> Signed-off-by: Dmitry Torokhov <dtor@google.com>
> Signed-off-by: Sarthak Kukreti <sarthakkukreti@google.com>
> ---
>  fs/ext4/hash-test.c | 14 ++++++++++++++
>  fs/ext4/hash.c      |  2 +-
>  fs/ext4/namei.c     |  9 +++++++--
>  3 files changed, 22 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ext4/hash-test.c b/fs/ext4/hash-test.c
> index 49b0d874c833..a8b206a6d751 100644
> --- a/fs/ext4/hash-test.c
> +++ b/fs/ext4/hash-test.c
> @@ -541,6 +541,20 @@ static void test_ext4fs_dirhash_casefold_fallback(struct kunit *test)
>  	KUNIT_ASSERT_EQ(test, ret_plain, 0);
>  	KUNIT_EXPECT_EQ(test, folded_dir.hash, plain.hash);
>  	KUNIT_EXPECT_EQ(test, folded_dir.minor_hash, plain.minor_hash);
> +
> +	ret_cf = ext4fs_dirhash(&ei->vfs_inode, ".\xe2\x80\xae", 4, &folded_dir);
> +	ret_plain = ext4fs_dirhash(plain_dir, ".\xe2\x80\xae", 4, &plain);
> +	KUNIT_ASSERT_EQ(test, ret_cf, 0);
> +	KUNIT_ASSERT_EQ(test, ret_plain, 0);
> +	KUNIT_EXPECT_EQ(test, folded_dir.hash, plain.hash);
> +	KUNIT_EXPECT_EQ(test, folded_dir.minor_hash, plain.minor_hash);
> +
> +	ret_cf = ext4fs_dirhash(&ei->vfs_inode, "\xe2\x80\xae", 3, &folded_dir);
> +	ret_plain = ext4fs_dirhash(plain_dir, "\xe2\x80\xae", 3, &plain);
> +	KUNIT_ASSERT_EQ(test, ret_cf, 0);
> +	KUNIT_ASSERT_EQ(test, ret_plain, 0);
> +	KUNIT_EXPECT_EQ(test, folded_dir.hash, plain.hash);
> +	KUNIT_EXPECT_EQ(test, folded_dir.minor_hash, plain.minor_hash);
>  }
>  #endif
>  
> diff --git a/fs/ext4/hash.c b/fs/ext4/hash.c
> index 978bd92da0ad..65019de4af93 100644
> --- a/fs/ext4/hash.c
> +++ b/fs/ext4/hash.c
> @@ -327,7 +327,7 @@ int ext4fs_dirhash(const struct inode *dir, const char *name, int len,
>  			return -ENOMEM;
>  
>  		dlen = utf8_casefold(um, &qstr, buff, PATH_MAX);
> -		if (dlen < 0) {
> +		if (dlen <= 0 || name_is_dot_dotdot(buff, dlen)) {
>  			kfree(buff);
>  			goto opaque_seq;
>  		}
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index 354fc2d22df1..cd2c9b873cc6 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -1368,7 +1368,8 @@ int ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname,
>  	int len;
>  
>  	if (!IS_CASEFOLDED(dir) ||
> -	    (IS_ENCRYPTED(dir) && !fscrypt_has_encryption_key(dir))) {
> +	    (IS_ENCRYPTED(dir) && !fscrypt_has_encryption_key(dir)) ||
> +	    name_is_dot_dotdot(iname->name, iname->len)) {

if name_is_dot_dotdot(iname->name, iname->len) is true, isn't that a
byte-exact match to dot or dotdot?  Do we actually get here for
byte-exact matches?

The rest of the patch looks good to me!

>  		cf_name->name = NULL;
>  		return 0;
>  	}
> @@ -1378,9 +1379,13 @@ int ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname,
>  		return -ENOMEM;
>  
>  	len = utf8_casefold(dir->i_sb->s_encoding, iname, buf, EXT4_NAME_LEN);
> -	if (len <= 0) {
> +	if (len < 0) {
>  		kfree(buf);
>  		buf = NULL;
> +	} else if (len == 0 || name_is_dot_dotdot(buf, len)) {
> +		kfree(buf);
> +		cf_name->name = NULL;
> +		return -EINVAL;
>  	}
>  	cf_name->name = buf;
>  	cf_name->len = (unsigned) len;
> -- 
> 2.56.1.750.gf70dc682cf-goog
>
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

-- 
Gabriel Krisman Bertazi

  reply	other threads:[~2026-11-24 19:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 21:49 [PATCH v2 0/3] fs: reject casefolded names that fold to ".", "..", or empty Sarthak Kukreti
2026-11-19 21:49 ` [PATCH v2 1/3] libfs: " Sarthak Kukreti
2026-11-24 19:36   ` [f2fs-dev] " Gabriel Krisman Bertazi
2026-11-19 21:49 ` [PATCH v2 2/3] ext4: " Sarthak Kukreti
2026-11-24 19:48   ` Gabriel Krisman Bertazi [this message]
2026-11-19 21:49 ` [PATCH v2 3/3] f2fs: " Sarthak Kukreti
2026-11-24 19:52   ` [f2fs-dev] " Gabriel Krisman Bertazi

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=87mrqyc8nr.fsf@cartola \
    --to=krisman@suse.de \
    --cc=brauner@kernel.org \
    --cc=chao@kernel.org \
    --cc=dtor@google.com \
    --cc=ebiggers@kernel.org \
    --cc=jaegeuk@kernel.org \
    --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=sarthakkukreti@google.com \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox