From: Eric Biggers <ebiggers@kernel.org>
To: Zhan Xusheng <zhanxusheng1024@gmail.com>
Cc: jaegeuk@kernel.org, chao@kernel.org,
linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, andrealmeid@igalia.com,
qkrwngud825@gmail.com, zhanxusheng@xiaomi.com,
Gabriel Krisman Bertazi <krisman@kernel.org>
Subject: Re: [RFC PATCH] f2fs: fold casefolded names of F2FS_NAME_LEN bytes
Date: Mon, 16 Nov 2026 19:48:45 +0000 [thread overview]
Message-ID: <20261116194845.GC229817@google.com> (raw)
In-Reply-To: <20261103030712.1514800-1-zhanxusheng1024@gmail.com>
[ +Cc Gabriel, who maintains fs/unicode/ ]
On Tue, Nov 03, 2026 at 11:07:12AM +0800, Zhan Xusheng wrote:
> From: Zhan Xusheng <zhanxusheng@xiaomi.com>
>
> utf8_casefold() needs room for the terminating NUL, but
> f2fs_init_casefolded_name() gives it only F2FS_NAME_LEN bytes, so a
> name that folds to exactly 255 bytes is not folded. In a casefolded
> directory, creating 'A' x 255 fails with EINVAL under utf8:strict.
> Without strict, after creating 'A' x 255, stat of 'a' x 255 returns
> ENOENT and creating it adds a second entry.
>
> Fold into F2FS_NAME_LEN + 1 bytes. Existing entries for these names
> are hashed by the name as given, so on a miss also try that hash.
>
> Fixes: 43c780ba2624 ("f2fs: rework filename handling")
> Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
> ---
> RFC because new entries for these names get a different hash on disk.
> Results in a VM, with dentries dropped before each stat:
>
> 'A'x255 'a'x255 'C'x255 'c'x255
> current kernel creates 'A' ok ENOENT
> this patch creates 'C', 'c' ok ENOENT ok ok
> (one 'c' entry)
> back on the current kernel ok ENOENT ENOENT ENOENT
> strict, current kernel create 'S' x 255: EINVAL
> strict, this patch create ok, found in both cases
>
> Each fsck.f2fs version matches only one side. 1.16 folds into PATH_MAX
> and rewrote 'A' to the folded hash, after which the current kernel
> cannot find it. The dev branch rewrote 'C' to the raw hash, after
> which this patch finds it only as 'C'. fsck would need to accept both
> hashes for these names. Encrypted directories are not tested.
>
> Is the second lookup acceptable? The alternative is to keep hashing
> these names as given, which fixes the EINVAL but leaves them
> case-sensitive.
Sorry about this bug!
I think it's actually worse than you say, and this commit doesn't fix it
entirely. A filename can "casefold" (really NFD canonical decomposition
+ Default_Ignorable_Code_Point stripping + full casefolding) to much
more than F2FS_NAME_LEN bytes. The decomposition stage in particular
can result in significant expansion, up to 3 * F2FS_NAME_LEN.
For ASCII though it is indeed as you say: they cannot expand, and only
max-length filenames are affected due to the off-by-one caused by
utf8_casefold() unexpectedly including a NUL terminator.
I think this shows that the 'casefold' feature` isn't really used for
anything other than ASCII in practice, and all the complexity of Unicode
normalization wasn't needed in the first place...
But I suppose this should be fixed anyway. The approach of this patch
should generally be okay if you increase the buffer to the required
'3 * F2FS_NAME_LEN + 1'.
However, please check the Sashiko comments
https://sashiko.dev/#/patchset/20261103030712.1514800-1-zhanxusheng1024%40gmail.com
as some issues were found with the implementation.
- Eric
next prev parent reply other threads:[~2026-11-16 19:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 3:07 Zhan Xusheng
2026-11-16 12:21 ` Zhan Xusheng
2026-11-16 19:48 ` Eric Biggers [this message]
2026-11-16 20:17 ` 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=20261116194845.GC229817@google.com \
--to=ebiggers@kernel.org \
--cc=andrealmeid@igalia.com \
--cc=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=krisman@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=qkrwngud825@gmail.com \
--cc=zhanxusheng1024@gmail.com \
--cc=zhanxusheng@xiaomi.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 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®