[PATCH v2 0/3] fs: reject casefolded names that fold to ".", "..", or empty

From: Sarthak Kukreti

Date: Thu Nov 19 2026 - 16:49:56 EST


Unicode normalization in fs/unicode strips Default_Ignorable_Code_Point
characters in both UTF8_NFDI and UTF8_NFDICF. In casefolded directories,
filenames consisting of 0 to 2 ASCII dots plus ignorable code points
(e.g. "\u202e", ".\u202e", "..\u202e") pass VFS path walk as normal
multi-byte components, but fold to "", ".", or ".." in utf8_casefold():

1. Looking up ".\u202e" folds to "." and matches the on-disk "." entry
(de->inode == dir->i_ino) in generic_ci_match(), triggering
EXT4_ERROR_INODE ("linked to parent dir") in ext4_lookup().
2. Looking up "..\u202e" folds to ".." and matches the on-disk ".."
entry, returning -ELOOP via d_splice_alias() (or triggering
EXT4_ERROR_INODE on the root directory).
3. Filenames consisting solely of ignorable characters fold to "" (0
bytes). On ext4, the first such file is created on disk and
subsequent ignorable-only names collide with it (-EEXIST); on f2fs,
f2fs_init_casefolded_name() treats len == 0 as a fallback to raw
bytewise hashing/matching, writing multiple ignorable-only files to
disk that fsck.f2fs flags with hash mismatches.

This series rejects casefolding and case-insensitive matching of names
that fold to "", ".", or ".." across libfs (generic_ci_d_hash,
generic_ci_match, and generic_ci_validate_strict_name), ext4
(ext4_fname_setup_ci_filename and ext4fs_dirhash), and f2fs
(f2fs_init_casefolded_name), while preserving exact byte-equality
matching for genuine "." and ".." lookups (such as NFS ext4_get_parent)
and opaque byte fallback for invalid UTF-8 sequences in non-strict mode.

Changes in v2:
- Drop redundant generic_ci_d_compare() changes from patch 1.
- Add Fixes: tags for initial ext4 and f2fs casefolding support to patch 1.
- Clarify ext4 vs f2fs behavior for ignorable-only filenames.

Link: https://lore.kernel.org/r/20261113065332.929085-1-sarthakkukreti@xxxxxxxxxx # v1

Dmitry Torokhov (1):
f2fs: reject casefolded names that fold to ".", "..", or empty

Sarthak Kukreti (2):
libfs: reject casefolded names that fold to ".", "..", or empty
ext4: reject casefolded names that fold to ".", "..", or empty

fs/ext4/hash-test.c | 14 ++++++++++++++
fs/ext4/hash.c | 2 +-
fs/ext4/namei.c | 9 +++++++--
fs/f2fs/dir.c | 6 +++++-
fs/libfs.c | 32 +++++++++++++++++++++++++++++---
include/linux/fs.h | 31 ++++++++++++++++++-------------
6 files changed, 74 insertions(+), 20 deletions(-)

--
2.56.1.703.gf848ed807c-goog