From: Dmitry Torokhov Filenames consisting only of ignorable Unicode characters fold to empty strings, and names with leading dots and ignorable characters can fold to "." or "..". Allowing such names in casefolded directories can corrupt directory structure or cause confusion with special entries. Reject any non-dot names that fold to empty, ".", or ".." during casefolded name setup, while still allowing invalid UTF-8 sequences to be handled as opaque byte sequences when strict mode is not enabled. Fixes: 2c2eb7a300cd ("f2fs: Support case-insensitive file name lookups") Signed-off-by: Dmitry Torokhov Signed-off-by: Sarthak Kukreti --- fs/f2fs/dir.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index 97f7fef6b068..f1d40f818b35 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -77,13 +77,17 @@ int f2fs_init_casefolded_name(const struct inode *dir, len = utf8_casefold(sb->s_encoding, fname->usr_fname, buf, F2FS_NAME_LEN); - if (len <= 0) { + if (len < 0) { kmem_cache_free(f2fs_cf_name_slab, buf); if (sb_has_strict_encoding(sb)) return -EINVAL; /* fall back to treating name as opaque byte sequence */ return 0; } + if (len == 0 || name_is_dot_dotdot(buf, len)) { + kmem_cache_free(f2fs_cf_name_slab, buf); + return -EINVAL; + } fname->cf_name.name = buf; fname->cf_name.len = len; } -- 2.56.1.750.gf70dc682cf-goog