]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ext4: introduce linear search for dentries
authorTheodore Ts'o <tytso@mit.edu>
Sat, 8 Feb 2025 04:08:02 +0000 (23:08 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 19 Sep 2025 14:35:42 +0000 (16:35 +0200)
[ Upstream commit 9e28059d56649a7212d5b3f8751ec021154ba3dd ]

This patch addresses an issue where some files in case-insensitive
directories become inaccessible due to changes in how the kernel
function, utf8_casefold(), generates case-folded strings from the
commit 5c26d2f1d3f5 ("unicode: Don't special case ignorable code
points").

There are good reasons why this change should be made; it's actually
quite stupid that Unicode seems to think that the characters ❤ and ❤️
should be casefolded.  Unfortimately because of the backwards
compatibility issue, this commit was reverted in 231825b2e1ff.

This problem is addressed by instituting a brute-force linear fallback
if a lookup fails on case-folded directory, which does result in a
performance hit when looking up files affected by the changing how
thekernel treats ignorable Uniode characters, or when attempting to
look up non-existent file names.  So this fallback can be disabled by
setting an encoding flag if in the future, the system administrator or
the manufacturer of a mobile handset or tablet can be sure that there
was no opportunity for a kernel to insert file names with incompatible
encodings.

Fixes: 5c26d2f1d3f5 ("unicode: Don't special case ignorable code points")
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/ext4/namei.c
include/linux/fs.h

index 286f8fcb74cc9da8d2dc8356beedf65984d582e1..29c7c0b8295fb8e5a7ed8b285985c42c48588827 100644 (file)
@@ -1462,7 +1462,8 @@ static bool ext4_match(struct inode *parent,
                 * sure cf_name was properly initialized before
                 * considering the calculated hash.
                 */
-               if (IS_ENCRYPTED(parent) && fname->cf_name.name &&
+               if (sb_no_casefold_compat_fallback(parent->i_sb) &&
+                   IS_ENCRYPTED(parent) && fname->cf_name.name &&
                    (fname->hinfo.hash != EXT4_DIRENT_HASH(de) ||
                     fname->hinfo.minor_hash != EXT4_DIRENT_MINOR_HASH(de)))
                        return false;
@@ -1595,10 +1596,15 @@ static struct buffer_head *__ext4_find_entry(struct inode *dir,
                 * return.  Otherwise, fall back to doing a search the
                 * old fashioned way.
                 */
-               if (!IS_ERR(ret) || PTR_ERR(ret) != ERR_BAD_DX_DIR)
+               if (IS_ERR(ret) && PTR_ERR(ret) == ERR_BAD_DX_DIR)
+                       dxtrace(printk(KERN_DEBUG "ext4_find_entry: dx failed, "
+                                      "falling back\n"));
+               else if (!sb_no_casefold_compat_fallback(dir->i_sb) &&
+                        *res_dir == NULL && IS_CASEFOLDED(dir))
+                       dxtrace(printk(KERN_DEBUG "ext4_find_entry: casefold "
+                                      "failed, falling back\n"));
+               else
                        goto cleanup_and_exit;
-               dxtrace(printk(KERN_DEBUG "ext4_find_entry: dx failed, "
-                              "falling back\n"));
                ret = NULL;
        }
        nblocks = dir->i_size >> EXT4_BLOCK_SIZE_BITS(sb);
index a6de8d93838d1ce23e628b3a6ccf002dc980d150..37a01c9d9658362c5f8716730a247aa756e27f12 100644 (file)
@@ -1197,11 +1197,19 @@ extern int send_sigurg(struct file *file);
 #define SB_NOUSER       BIT(31)
 
 /* These flags relate to encoding and casefolding */
-#define SB_ENC_STRICT_MODE_FL  (1 << 0)
+#define SB_ENC_STRICT_MODE_FL          (1 << 0)
+#define SB_ENC_NO_COMPAT_FALLBACK_FL   (1 << 1)
 
 #define sb_has_strict_encoding(sb) \
        (sb->s_encoding_flags & SB_ENC_STRICT_MODE_FL)
 
+#if IS_ENABLED(CONFIG_UNICODE)
+#define sb_no_casefold_compat_fallback(sb) \
+       (sb->s_encoding_flags & SB_ENC_NO_COMPAT_FALLBACK_FL)
+#else
+#define sb_no_casefold_compat_fallback(sb) (1)
+#endif
+
 /*
  *     Umount options
  */