From: sashiko-bot@kernel.org
To: "Mingbing Zhai" <zhaimingbing@cmss.chinamobile.com>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH] ext4: load the casefold encoding when it is enabled online
Date: Wed, 02 Dec 2026 10:16:07 +0000 [thread overview]
Message-ID: <sashiko-outbox-245412@kernel.org> (raw)
In-Reply-To: <20261202100056.1419-1-zhaimingbing@cmss.chinamobile.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] ext4: missing Signed-off-by trailer in commit message
- [High] ext4: ext4_ioctl_set_tune_sb() misses generic_ci_dentry_ops on
casefold enable
- [Medium] ext4: ext4_ioctl_set_tune_sb() enables casefold before
ext4_encoding_init()
- [Medium] ext4: concurrent ext4_encoding_init() calls leak unicode_map
and module ref
- [Medium] ext4: test_validate_tune_sb_params() fails when
CONFIG_UNICODE is disabled
--
commit 091d1e5fe40a962324e509a8c40b8bbc5b4f7c7d
Author: Mingbing Zhai <zhaimingbing@cmss.chinamobile.com>
> ext4: load the casefold encoding when it is enabled online
>
> EXT4_IOC_SET_TUNE_SB_PARAM can enable casefold on a mounted
> filesystem, but the runtime unicode map (sb->s_encoding) is only
> built by ext4_encoding_init() from the mount path. With the feature
> bit set and sb->s_encoding left NULL, a lookup in a casefolded
> directory dereferences NULL:
>
> KASAN: null-ptr-deref in utf8nlookup fs/unicode/utf8-norm.c:306
> ext4_fname_setup_ci_filename fs/ext4/namei.c:1226
> ext4_lookup fs/ext4/namei.c:1619
>
> Load the encoding after enabling the feature, and refuse to enable
> it when the kernel has no unicode support, like the mount path does.
>
> Fixes: 04a91570ac67 ("ext4: implemet new ioctls to set and get superblock parameters")
> Reported-by: syzbot+68178aa1e39c8606392e@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=68178aa1e39c8606392e
> Reported-by: Guikun Yang <yangguikun19@qq.com>
> Link: https://lore.kernel.org/r/tencent_B079992E4541FB5447D9A4067D6F8D40380A@qq.com
> Cc: stable@vger.kernel.org
[Severity: High]
The commit message is missing a Signed-off-by: trailer.
> diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
> index 83630cd40712c..f227304d3490c 100644
> --- a/fs/ext4/ioctl.c
> +++ b/fs/ext4/ioctl.c
> @@ -1480,6 +1480,8 @@ static int ext4_validate_tune_sb_params(struct super_block *sb,
> if (params->set_feature_incompat_mask &
> EXT4_FEATURE_INCOMPAT_CASEFOLD) {
> enabling_casefold = 1;
> + if (!IS_ENABLED(CONFIG_UNICODE))
> + return -EOPNOTSUPP;
> if (!(params->set_flags & EXT4_TUNE_FL_ENCODING)) {
> params->encoding = EXT4_ENC_UTF8_12_1;
> params->set_flags |= EXT4_TUNE_FL_ENCODING;
[Severity: Medium]
Does this break test_validate_tune_sb_params() when CONFIG_UNICODE is
disabled?
CONFIG_EXT4_KUNIT_TESTS does not depend on CONFIG_UNICODE, and
test_validate_tune_sb_params() in fs/ext4/ioctl-test.c unconditionally
expects 0 when enabling EXT4_FEATURE_INCOMPAT_CASEFOLD:
fs/ext4/ioctl-test.c:test_validate_tune_sb_params() {
...
memset(¶ms, 0, sizeof(params));
params.set_flags = EXT4_TUNE_FL_EDIT_FEATURES;
params.set_feature_incompat_mask = EXT4_FEATURE_INCOMPAT_CASEFOLD;
KUNIT_EXPECT_EQ(test, ext4_validate_tune_sb_params_test(sb, ¶ms),
0);
KUNIT_EXPECT_EQ(test, params.encoding, EXT4_ENC_UTF8_12_1);
KUNIT_EXPECT_EQ(test, params.encoding_flags, 0);
...
}
Also, EXT4_TUNE_SET_INCOMPAT_SUPP still includes
EXT4_FEATURE_INCOMPAT_CASEFOLD unconditionally, so
ext4_ioctl_get_tune_sb() continues to advertise casefold as supported when
!IS_ENABLED(CONFIG_UNICODE).
> @@ -1555,6 +1557,15 @@ static int ext4_ioctl_set_tune_sb(struct file *filp,
> return ret;
>
> ret = ext4_update_superblocks_fn(sb, ext4_sb_setparams, ¶ms);
> +
> + if ((params.set_feature_incompat_mask &
> + EXT4_FEATURE_INCOMPAT_CASEFOLD) &&
> + ext4_has_feature_casefold(sb)) {
> + int err = ext4_encoding_init(sb, sbi->s_es);
> +
> + if (err && !ret)
> + ret = err;
> + }
> mnt_drop_write_file(filp);
[Severity: High]
Does enabling casefold online leave the VFS dcache without
generic_ci_dentry_ops?
On the mount path in __ext4_fill_super(), ext4_encoding_init() runs before
generic_set_sb_d_ops(sb) and d_make_root(root), which sets
sb->__s_d_op = &generic_ci_dentry_ops and adds DCACHE_OP_HASH |
DCACHE_OP_COMPARE to sb->s_d_flags. When a filesystem is mounted without
casefold, sb->s_encoding is NULL at mount time, so generic_ci_dentry_ops is
not installed.
Calling ext4_encoding_init() later from ext4_ioctl_set_tune_sb() populates
sb->s_encoding without updating sb->__s_d_op, sb->s_d_flags, or existing
cached dentries. As a result, VFS dcache lookups in casefolded directories
remain case-sensitive while ext4_lookup() matches case-insensitively on
disk, creating duplicate positive dentry aliases with different casings for
the same regular file inode and bypassing SB_ENC_STRICT_MODE_FL UTF-8
checks in generic_ci_d_hash().
[Severity: Medium]
Can setting EXT4_FEATURE_INCOMPAT_CASEFOLD in ext4_update_superblocks_fn()
before ext4_encoding_init() still leave sb->s_encoding NULL while
ext4_has_feature_casefold(sb) is true?
CPU0 CPU1
ext4_ioctl_set_tune_sb()
ext4_update_superblocks_fn()
ext4_update_primary_sb()
ext4_sb_setparams()
/* sets CASEFOLD in s_es */
ext4_fileattr_set()
/* sets EXT4_CASEFOLD_FL */
ext4_lookup()
...
utf8nlookup()
/* NULL deref on s_encoding */
ext4_encoding_init()
sb->s_encoding = encoding;
ext4_update_primary_sb() and the backup superblock loop perform synchronous
buffer I/O after EXT4_FEATURE_INCOMPAT_CASEFOLD is already live in
sbi->s_es. In addition, if ext4_encoding_init() fails (for example when
utf8_load() fails to load utf8data.ko or runs out of memory), the feature
bit is not rolled back in sbi->s_es or on disk, and retrying
EXT4_IOC_SET_TUNE_SB_PARAM cannot initialize sb->s_encoding because
ext4_validate_tune_sb_params() masks out features already set in
es->s_feature_incompat.
[Severity: Medium]
Can concurrent EXT4_IOC_SET_TUNE_SB_PARAM calls race in
ext4_encoding_init() and leak a struct unicode_map and utf8data module
reference?
Both ext4_validate_tune_sb_params() and ext4_encoding_init() run outside
the EXT4_FLAGS_RESIZING lock used by ext4_update_superblocks_fn(), and
ext4_encoding_init() is called even when ext4_update_superblocks_fn()
returns -EBUSY. Two threads enabling casefold concurrently can both retain
EXT4_FEATURE_INCOMPAT_CASEFOLD in params.set_feature_incompat_mask, both
observe sb->s_encoding == NULL in ext4_encoding_init(), and both call
utf8_load(), overwriting the first sb->s_encoding pointer and leaking its
allocation and symbol_request(utf8_data_table) reference.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202100056.1419-1-zhaimingbing@cmss.chinamobile.com?part=1
prev parent reply other threads:[~2026-12-02 10:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 10:00 [PATCH] ext4: load the casefold encoding when it is enabled online Mingbing Zhai
2026-12-02 10:16 ` sashiko-bot [this message]
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=sashiko-outbox-245412@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tytso@mit.edu \
--cc=zhaimingbing@cmss.chinamobile.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.