From: Sarthak Kukreti <sarthakkukreti@google.com>
To: "Theodore Ts'o" <tytso@mit.edu>, Jaegeuk Kim <jaegeuk@kernel.org>,
Chao Yu <chao@kernel.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>
Cc: Gabriel Krisman Bertazi <krisman@collabora.co.uk>,
Eric Biggers <ebiggers@google.com>,
Dmitry Torokhov <dtor@google.com>,
linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org,
Sarthak Kukreti <sarthakkukreti@google.com>
Subject: [PATCH 2/3] ext4: reject casefolded names that fold to ".", "..", or empty
Date: Thu, 12 Nov 2026 22:53:31 -0800 [thread overview]
Message-ID: <20261113065332.929085-3-sarthakkukreti@google.com> (raw)
In-Reply-To: <20261113065332.929085-1-sarthakkukreti@google.com>
Filenames consisting solely of ignorable Unicode characters fold to
empty strings, while names with leading dots and ignorable characters
fold to "." or "..". Allowing such names to be created or looked up in
casefolded directories collides with on-disk "." and ".." entries (which
triggers EXT4_ERROR_INODE in ext4_lookup()) and introduces duplicate
entries that e2fsck flags as corruption.
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 a6386c1d237f..096f78ea5df4 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)) {
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.0.611.g1030f0b940-goog
next prev parent reply other threads:[~2026-11-13 6:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 6:53 [PATCH 0/3] fs: " Sarthak Kukreti
2026-11-13 6:53 ` [PATCH 1/3] libfs: " Sarthak Kukreti
2026-11-16 19:34 ` Gabriel Krisman Bertazi
2026-11-16 20:05 ` Eric Biggers
2026-11-13 6:53 ` Sarthak Kukreti [this message]
2026-11-13 6:53 ` [PATCH 3/3] f2fs: " Sarthak Kukreti
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=20261113065332.929085-3-sarthakkukreti@google.com \
--to=sarthakkukreti@google.com \
--cc=brauner@kernel.org \
--cc=chao@kernel.org \
--cc=dtor@google.com \
--cc=ebiggers@google.com \
--cc=jaegeuk@kernel.org \
--cc=krisman@collabora.co.uk \
--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 \
/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
all inboxes | Powered by JetHome®