Root Cause
The crash is a NULL-pointer dereference in utf8nlookup() (fs/unicode/utf8-norm.c:306) caused by an ext4 directory having S_CASEFOLD (IS_CASEFOLDED(dir)) set while dir->i_sb->s_encoding is NULL:
static utf8leaf_t *utf8nlookup(const struct unicode_map *um,
enum utf8_normalization n, unsigned char *hangul, const char *s,
size_t len)
{
utf8trie_t *trie = um->tables->utf8data + um->ntab[n]->offset;
In the crash report, %r13 (um) is NULL, and 0x18(%r13) is um->tables (offset 0x18 in struct unicode_map), producing the KASAN report at [0x0000000000000018-0x000000000000001f].
Normally, ext4 enforces the invariant that IS_CASEFOLDED(inode) implies sb->s_encoding != NULL (when CONFIG_UNICODE=y):
- At mount time,
__ext4_fill_super() (fs/ext4/super.c:5519) calls ext4_encoding_init(sb, es), which loads the UTF-8 map via utf8_load() into sb->s_encoding if ext4_has_feature_casefold(sb) is true (and fails the mount otherwise). generic_set_sb_d_ops(sb) (fs/ext4/super.c:5729) then installs generic_ci_dentry_ops only if sb->s_encoding is non-NULL.
- If
EXT4_FEATURE_INCOMPAT_CASEFOLD was not set at mount time, sb->s_encoding remains NULL.
However, ext4_ioctl_set_tune_sb() (EXT4_IOC_SET_TUNE_SB_PARAM, fs/ext4/ioctl.c:1535) breaks this invariant on a live mounted filesystem:
EXT4_TUNE_SET_INCOMPAT_SUPP (fs/ext4/ioctl.c:1278) includes EXT4_FEATURE_INCOMPAT_CASEFOLD, and ext4_validate_tune_sb_params() (fs/ext4/ioctl.c:1480-1493) explicitly allows enabling EXT4_FEATURE_INCOMPAT_CASEFOLD (defaulting params->encoding = EXT4_ENC_UTF8_12_1 and params->encoding_flags = 0).
ext4_update_superblocks_fn(sb, ext4_sb_setparams, ¶ms) updates the superblock buffer sbi->s_es (es->s_feature_incompat |= EXT4_FEATURE_INCOMPAT_CASEFOLD, es->s_encoding, es->s_encoding_flags).
ext4_ioctl_set_tune_sb() never initializes sb->s_encoding or sb->s_encoding_flags (i.e., it never calls ext4_encoding_init()), nor does it check CONFIG_UNICODE or set sb->s_d_op (generic_set_sb_d_ops()).
Trigger Path
- An ext4 filesystem is mounted without
EXT4_FEATURE_INCOMPAT_CASEFOLD, so sb->s_encoding is NULL.
ioctl(..., EXT4_IOC_SET_TUNE_SB_PARAM, ...) enables EXT4_FEATURE_INCOMPAT_CASEFOLD on sbi->s_es, causing ext4_has_feature_casefold(sb) to return true while sb->s_encoding stays NULL.
ext4_ioctl_setflags() (fs/ext4/ioctl.c:631-635) / ext4_fileattr_set() checks only !ext4_has_feature_casefold(sb) (not sb->s_encoding) and therefore allows setting EXT4_CASEFOLD_FL (S_CASEFOLD) on an empty directory (similarly, __ext4_iget() at fs/ext4/inode.c:6674 only checks !ext4_has_feature_casefold(inode->i_sb)).
- Any subsequent lookup inside that directory (here triggered by
do_mount -> user_path_at -> filename_lookup -> ext4_lookup) reaches:
ext4_lookup_entry() (fs/ext4/namei.c:1547)
ext4_fname_prepare_lookup() (fs/ext4/crypto.c:54)
ext4_fname_setup_ci_filename() (fs/ext4/namei.c:1226), which checks IS_CASEFOLDED(dir) without checking dir->i_sb->s_encoding and calls utf8_casefold(dir->i_sb->s_encoding, iname, buf, EXT4_NAME_LEN) with um == NULL.
utf8_casefold() (fs/unicode/utf8-core.c:106-110) initializes u8c->um = NULL in utf8ncursor() and calls utf8byte() -> utf8nlookup(), which dereferences um->tables at NULL + 0x18.
Note that other ext4 casefold paths (such as ext4fs_dirhash() in fs/ext4/hash.c:318-329 and generic_ci_d_hash() / generic_ci_match() in fs/libfs.c) also assume sb->s_encoding != NULL whenever IS_CASEFOLDED(dir) is true.