Skip to content

Commit 9e28059

Browse files
committed
ext4: introduce linear search for dentries
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 5c26d2f ("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 231825b. 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: 5c26d2f ("unicode: Don't special case ignorable code points") Signed-off-by: Theodore Ts'o <[email protected]> Reviewed-by: Gabriel Krisman Bertazi <[email protected]>
1 parent a399af4 commit 9e28059

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

fs/ext4/namei.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,8 @@ static bool ext4_match(struct inode *parent,
14621462
* sure cf_name was properly initialized before
14631463
* considering the calculated hash.
14641464
*/
1465-
if (IS_ENCRYPTED(parent) && fname->cf_name.name &&
1465+
if (sb_no_casefold_compat_fallback(parent->i_sb) &&
1466+
IS_ENCRYPTED(parent) && fname->cf_name.name &&
14661467
(fname->hinfo.hash != EXT4_DIRENT_HASH(de) ||
14671468
fname->hinfo.minor_hash != EXT4_DIRENT_MINOR_HASH(de)))
14681469
return false;
@@ -1595,10 +1596,15 @@ static struct buffer_head *__ext4_find_entry(struct inode *dir,
15951596
* return. Otherwise, fall back to doing a search the
15961597
* old fashioned way.
15971598
*/
1598-
if (!IS_ERR(ret) || PTR_ERR(ret) != ERR_BAD_DX_DIR)
1599+
if (IS_ERR(ret) && PTR_ERR(ret) == ERR_BAD_DX_DIR)
1600+
dxtrace(printk(KERN_DEBUG "ext4_find_entry: dx failed, "
1601+
"falling back\n"));
1602+
else if (!sb_no_casefold_compat_fallback(dir->i_sb) &&
1603+
*res_dir == NULL && IS_CASEFOLDED(dir))
1604+
dxtrace(printk(KERN_DEBUG "ext4_find_entry: casefold "
1605+
"failed, falling back\n"));
1606+
else
15991607
goto cleanup_and_exit;
1600-
dxtrace(printk(KERN_DEBUG "ext4_find_entry: dx failed, "
1601-
"falling back\n"));
16021608
ret = NULL;
16031609
}
16041610
nblocks = dir->i_size >> EXT4_BLOCK_SIZE_BITS(sb);

include/linux/fs.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,11 +1258,19 @@ extern int send_sigurg(struct file *file);
12581258
#define SB_NOUSER BIT(31)
12591259

12601260
/* These flags relate to encoding and casefolding */
1261-
#define SB_ENC_STRICT_MODE_FL (1 << 0)
1261+
#define SB_ENC_STRICT_MODE_FL (1 << 0)
1262+
#define SB_ENC_NO_COMPAT_FALLBACK_FL (1 << 1)
12621263

12631264
#define sb_has_strict_encoding(sb) \
12641265
(sb->s_encoding_flags & SB_ENC_STRICT_MODE_FL)
12651266

1267+
#if IS_ENABLED(CONFIG_UNICODE)
1268+
#define sb_no_casefold_compat_fallback(sb) \
1269+
(sb->s_encoding_flags & SB_ENC_NO_COMPAT_FALLBACK_FL)
1270+
#else
1271+
#define sb_no_casefold_compat_fallback(sb) (1)
1272+
#endif
1273+
12661274
/*
12671275
* Umount options
12681276
*/

0 commit comments

Comments
 (0)