* [PATCH v3] ext4: fix NULL s_encoding after runtime tune_sb enables casefold
@ 2026-12-03 1:30 Shuai Liu
2026-12-03 1:47 ` sashiko-bot
2026-12-03 11:40 ` kernel test robot
0 siblings, 2 replies; 3+ messages in thread
From: Shuai Liu @ 2026-12-03 1:30 UTC (permalink / raw)
To: linux-ext4
Cc: tytso, jack, adilger.kernel, libaokun, ojaswin, ritesh.list,
yi.zhang, djwong, zhaimingbing, linux-fsdevel, linux-kernel,
syzbot+68178aa1e39c8606392e, Shuai Liu
When EXT4_IOC_SET_TUNE_SB_PARAM is used at runtime to enable the
CASEFOLD incompat feature, ext4_validate_tune_sb_params() auto-sets
encoding parameters (defaulting to UTF8_12_1), and ext4_sb_setparams()
updates the on-disk superblock and the in-memory sbi->s_es copy.
However, ext4_ioctl_set_tune_sb() never calls ext4_encoding_init()
to actually load sb->s_encoding.
This leaves sb->s_encoding as NULL while ext4_has_feature_casefold()
returns true. A subsequent FS_IOC_SETFLAGS setting FS_CASEFOLD_FL on
a directory succeeds, and any lookup in that directory calls
ext4_match() or ext4_fname_setup_ci_filename() which invoke
utf8_casefold() or generic_ci_match() with a NULL um pointer.
Reproducer trace from syzbot:
mount(ext4) -> EXT4_IOC_SET_TUNE_SB_PARAM(enables casefold) ->
mkdir -> FS_IOC_SETFLAGS(FS_CASEFOLD_FL) -> open triggers lookup ->
utf8_casefold(NULL, ...) -> utf8nlookup+0x39 NULL ptr deref -> GPF
Fix this by:
- loading sb->s_encoding when runtime tune_sb enables casefold. The
encoding is probed (utf8_load + utf8_unload) before the feature is
committed so a load failure cannot leave an on-disk CASEFOLD feature
that the filesystem can never mount again. sb->s_encoding is
published after the superblock update, under a mutex shared by
concurrent tune_sb callers so that only one unicode_map is loaded.
- publishing sb->s_encoding with smp_store_release() in
ext4_encoding_init() so that lockless readers never observe a
non-NULL map before utf8_load()'s internal stores are visible.
- adding NULL guards with READ_ONCE() on the sb->s_encoding reads in
ext4_match(), ext4_fname_setup_ci_filename() and ext4fs_dirhash()
so that the transient feature-vs-encoding window cannot dereference
a NULL map.
- rejecting runtime casefold enablement in
ext4_validate_tune_sb_params() when CONFIG_UNICODE is disabled;
otherwise the feature would be committed while s_encoding can never
be loaded.
The ext4_encoding_init() stub is moved from super.c into ext4.h so it
is available to callers in other translation units.
Note that rejecting runtime casefold enablement altogether (leaving it
to offline tune2fs) would avoid the feature-flag vs. s_encoding
visibility window entirely. This fix keeps the feature usable at
runtime since that is what the ioctl is designed for, at the cost of
the guards above; if offline-only enablement is preferred, the probe
and publish can be dropped and the request rejected in
ext4_validate_tune_sb_params() instead.
Verified with QEMU/KASAN two-state testing of the reproducer chain
above: the unpatched kernel reports GPF in utf8nlookup, the patched
kernel completes 1000 lookups in the casefolded directory cleanly.
Fixes: 04a91570ac67 ("ext4: implemet new ioctls to set and get superblock parameters")
Link: https://syzbot.org/bug?extid=68178aa1e39c8606392e
Link: https://lore.kernel.org/all/20261202100056.1419-1-zhaimingbing@cmss.chinamobile.com/
Reported-by: syzbot+68178aa1e39c8606392e@syzkaller.appspotmail.com
Closes: https://syzbot.org/bug?extid=68178aa1e39c8606392e
Signed-off-by: Shuai Liu <847807867@qq.com>
---
An independent fix for this bug was posted by Mingbing Zhai (Link
above). This version additionally probes the encoding before the
feature is committed (a failed utf8_load() after commit leaves an
on-disk CASEFOLD feature that the filesystem can never mount again),
serialises concurrent tune_sb callers so that only one unicode_map is
loaded, publishes s_encoding with release ordering, and guards the
feature-vs-encoding window in the lookup paths.
Changes in v3:
- Drop generic_set_sb_d_ops() call: updating sb->s_d_op at runtime races
with concurrent __d_alloc() readers of __s_d_op (Sashiko)
- Probe encoding loadability before committing the CASEFOLD feature, and
publish sb->s_encoding after the superblock update instead of loading
after mnt_drop_write_file(); prevents both an unmountable filesystem
when utf8_load() fails and the feature-committed-but-encoding-NULL
window (Sashiko)
- Serialise concurrent tune_sb enablement with a mutex to avoid leaking
a unicode_map (Sashiko)
- Publish s_encoding with smp_store_release() before s_encoding_flags
(Sashiko)
- Reject runtime casefold enablement when CONFIG_UNICODE=n (Sashiko)
- Found during QEMU verification: the feature gate in ext4_encoding_init()
must be kept; an earlier revision dropped it and broke mount on every
ext4 filesystem without casefold
Changes in v2:
- Add NULL guard in ext4_match() and use READ_ONCE() on the s_encoding
reads in ext4_match(), ext4_fname_setup_ci_filename() and
ext4fs_dirhash() (Sashiko)
- Call ext4_encoding_init() while still holding the mnt write access
(Sashiko)
- Add Fixes tag (Sashiko)
- Move the ext4_encoding_init() stub for CONFIG_UNICODE=n into ext4.h
fs/ext4/ext4.h | 12 ++++++++++++
fs/ext4/hash.c | 3 ++-
fs/ext4/ioctl.c | 31 +++++++++++++++++++++++++++++++
fs/ext4/namei.c | 6 +++++-
fs/ext4/super.c | 40 +++++++++++++++++++++++++++++++---------
5 files changed, 81 insertions(+), 11 deletions(-)
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index dc2c181337a16..c6a338ae44f5d 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2958,6 +2958,8 @@ extern unsigned ext4_free_clusters_after_init(struct super_block *sb,
ext4_fsblk_t ext4_inode_to_goal_block(struct inode *);
#if IS_ENABLED(CONFIG_UNICODE)
+extern int ext4_encoding_init(struct super_block *sb, struct ext4_super_block *es);
+extern int ext4_encoding_probe(struct super_block *sb, __u16 encoding_id);
extern int ext4_fname_setup_ci_filename(struct inode *dir,
const struct qstr *iname,
struct ext4_filename *fname);
@@ -2968,6 +2970,16 @@ static inline void ext4_fname_free_ci_filename(struct ext4_filename *fname)
fname->cf_name.name = NULL;
}
#else
+static inline int ext4_encoding_init(struct super_block *sb, struct ext4_super_block *es)
+{
+ return 0;
+}
+
+static inline int ext4_encoding_probe(struct super_block *sb, __u16 encoding_id)
+{
+ return 0;
+}
+
static inline int ext4_fname_setup_ci_filename(struct inode *dir,
const struct qstr *iname,
struct ext4_filename *fname)
diff --git a/fs/ext4/hash.c b/fs/ext4/hash.c
index 978bd92da0ad3..59c40b313d267 100644
--- a/fs/ext4/hash.c
+++ b/fs/ext4/hash.c
@@ -315,12 +315,13 @@ int ext4fs_dirhash(const struct inode *dir, const char *name, int len,
struct dx_hash_info *hinfo)
{
#if IS_ENABLED(CONFIG_UNICODE)
- const struct unicode_map *um = dir->i_sb->s_encoding;
+ const struct unicode_map *um = READ_ONCE(dir->i_sb->s_encoding);
int r, dlen;
unsigned char *buff;
struct qstr qstr = {.name = name, .len = len };
if (len && IS_CASEFOLDED(dir) &&
+ um &&
(!IS_ENCRYPTED(dir) || fscrypt_has_encryption_key(dir))) {
buff = kzalloc(PATH_MAX, GFP_KERNEL);
if (!buff)
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 83630cd40712c..515ac455074d2 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -1479,6 +1479,8 @@ static int ext4_validate_tune_sb_params(struct super_block *sb,
~le32_to_cpu(es->s_feature_ro_compat);
if (params->set_feature_incompat_mask &
EXT4_FEATURE_INCOMPAT_CASEFOLD) {
+ if (!IS_ENABLED(CONFIG_UNICODE))
+ return -EINVAL;
enabling_casefold = 1;
if (!(params->set_flags & EXT4_TUNE_FL_ENCODING)) {
params->encoding = EXT4_ENC_UTF8_12_1;
@@ -1539,6 +1541,7 @@ static int ext4_ioctl_set_tune_sb(struct file *filp,
struct super_block *sb = file_inode(filp)->i_sb;
struct ext4_sb_info *sbi = EXT4_SB(sb);
int ret;
+ bool enabling_casefold;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
@@ -1550,11 +1553,39 @@ static int ext4_ioctl_set_tune_sb(struct file *filp,
if (ret)
return ret;
+ enabling_casefold = (params.set_flags & EXT4_TUNE_FL_EDIT_FEATURES) &&
+ (params.set_feature_incompat_mask &
+ EXT4_FEATURE_INCOMPAT_CASEFOLD) &&
+ !ext4_has_feature_casefold(sb);
+
ret = mnt_want_write_file(filp);
if (ret)
return ret;
+ /* A failed utf8_load() after commit leaves an unmountable fs. */
+ if (enabling_casefold && !READ_ONCE(sb->s_encoding)) {
+ ret = ext4_encoding_probe(sb, params.encoding);
+ if (ret) {
+ mnt_drop_write_file(filp);
+ return ret;
+ }
+ }
+
ret = ext4_update_superblocks_fn(sb, ext4_sb_setparams, ¶ms);
+
+ /* Serialise concurrent callers: only one unicode_map may load. */
+ if (ret == 0 && enabling_casefold) {
+ static DEFINE_MUTEX(casefold_enable_lock);
+
+ mutex_lock(&casefold_enable_lock);
+ ret = ext4_encoding_init(sb, sbi->s_es);
+ mutex_unlock(&casefold_enable_lock);
+ if (ret)
+ ext4_msg(sb, KERN_ERR,
+ "runtime tune_sb: encoding_init failed (%d)",
+ ret);
+ }
+
mnt_drop_write_file(filp);
if (params.set_flags & EXT4_TUNE_FL_DEF_HASH_ALG)
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index b2753daad49f4..0daa6a4bba30d 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -1211,9 +1211,12 @@ int ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname,
struct qstr *cf_name = &name->cf_name;
unsigned char *buf;
struct dx_hash_info *hinfo = &name->hinfo;
+ const struct unicode_map *um;
int len;
+ um = READ_ONCE(dir->i_sb->s_encoding);
if (!IS_CASEFOLDED(dir) ||
+ !um ||
(IS_ENCRYPTED(dir) && !fscrypt_has_encryption_key(dir))) {
cf_name->name = NULL;
return 0;
@@ -1223,7 +1226,7 @@ int ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname,
if (!buf)
return -ENOMEM;
- len = utf8_casefold(dir->i_sb->s_encoding, iname, buf, EXT4_NAME_LEN);
+ len = utf8_casefold(um, iname, buf, EXT4_NAME_LEN);
if (len <= 0) {
kfree(buf);
buf = NULL;
@@ -1266,6 +1269,7 @@ static bool ext4_match(struct inode *parent,
#if IS_ENABLED(CONFIG_UNICODE)
if (IS_CASEFOLDED(parent) &&
+ READ_ONCE(parent->i_sb->s_encoding) &&
(!IS_ENCRYPTED(parent) || fscrypt_has_encryption_key(parent))) {
/*
* Just checking IS_ENCRYPTED(parent) below is not
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 880f664d6c04b..37431e0ffbfab 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -2055,9 +2055,8 @@ static const struct ext4_sb_encodings {
};
static const struct ext4_sb_encodings *
-ext4_sb_read_encoding(const struct ext4_super_block *es)
+ext4_sb_read_encoding(__u16 magic)
{
- __u16 magic = le16_to_cpu(es->s_encoding);
int i;
for (i = 0; i < ARRAY_SIZE(ext4_sb_encoding_map); i++)
@@ -4737,16 +4736,16 @@ static int ext4_inode_info_init(struct super_block *sb,
}
#if IS_ENABLED(CONFIG_UNICODE)
-static int ext4_encoding_init(struct super_block *sb, struct ext4_super_block *es)
+int ext4_encoding_init(struct super_block *sb, struct ext4_super_block *es)
{
const struct ext4_sb_encodings *encoding_info;
struct unicode_map *encoding;
__u16 encoding_flags = le16_to_cpu(es->s_encoding_flags);
- if (!ext4_has_feature_casefold(sb) || sb->s_encoding)
+ if (!ext4_has_feature_casefold(sb) || READ_ONCE(sb->s_encoding))
return 0;
- encoding_info = ext4_sb_read_encoding(es);
+ encoding_info = ext4_sb_read_encoding(le16_to_cpu(es->s_encoding));
if (!encoding_info) {
ext4_msg(sb, KERN_ERR,
"Encoding requested by superblock is unknown");
@@ -4765,6 +4764,7 @@ static int ext4_encoding_init(struct super_block *sb, struct ext4_super_block *e
encoding_flags);
return -EINVAL;
}
+
ext4_msg(sb, KERN_INFO,"Using encoding defined by superblock: "
"%s-%u.%u.%u with flags 0x%hx", encoding_info->name,
unicode_major(encoding_info->version),
@@ -4772,14 +4772,36 @@ static int ext4_encoding_init(struct super_block *sb, struct ext4_super_block *e
unicode_rev(encoding_info->version),
encoding_flags);
- sb->s_encoding = encoding;
- sb->s_encoding_flags = encoding_flags;
+ /* Order wrt utf8_load() stores inside *encoding */
+ smp_store_release(&sb->s_encoding, encoding);
+ WRITE_ONCE(sb->s_encoding_flags, encoding_flags);
return 0;
}
-#else
-static inline int ext4_encoding_init(struct super_block *sb, struct ext4_super_block *es)
+
+int ext4_encoding_probe(struct super_block *sb, __u16 encoding_id)
{
+ const struct ext4_sb_encodings *encoding_info;
+ struct unicode_map *encoding;
+
+ encoding_info = ext4_sb_read_encoding(encoding_id);
+ if (!encoding_info) {
+ ext4_msg(sb, KERN_ERR, "Encoding requested by tune_sb is unknown");
+ return -EINVAL;
+ }
+
+ encoding = utf8_load(encoding_info->version);
+ if (IS_ERR(encoding)) {
+ ext4_msg(sb, KERN_ERR,
+ "casefold charset %s-%u.%u.%u not supported",
+ encoding_info->name,
+ unicode_major(encoding_info->version),
+ unicode_minor(encoding_info->version),
+ unicode_rev(encoding_info->version));
+ return -EINVAL;
+ }
+
+ utf8_unload(encoding);
return 0;
}
#endif
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] ext4: fix NULL s_encoding after runtime tune_sb enables casefold
2026-12-03 1:30 [PATCH v3] ext4: fix NULL s_encoding after runtime tune_sb enables casefold Shuai Liu
@ 2026-12-03 1:47 ` sashiko-bot
2026-12-03 11:40 ` kernel test robot
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-03 1:47 UTC (permalink / raw)
To: Shuai Liu, linux-ext4; +Cc: tytso
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] ext4: build failure in ext4_ioctl_set_tune_sb() when
CONFIG_UNICODE=n
- [Medium] ext4: runtime casefold enablement in ext4_ioctl_set_tune_sb()
lacks ci d_op
- [Medium] ext4: ext4_ioctl_set_tune_sb() sets CASEFOLD before loading
sb->s_encoding
- [Low] ext4: test_validate_tune_sb_params() KUnit test fails when
CONFIG_UNICODE=n
- [Low] ext4: ext4_encoding_init() publishes s_encoding before
s_encoding_flags
- [Low] ext4: unsynchronized validation in ext4_ioctl_set_tune_sb()
desyncs flags
--
commit e4196145e161d5e5b3c49424062eabb6e3109d72
Author: Shuai Liu <847807867@qq.com>
ext4: fix NULL s_encoding after runtime tune_sb enables casefold
This commit probes and initializes sb->s_encoding when
EXT4_IOC_SET_TUNE_SB_PARAM enables the casefold feature at runtime, adds
READ_ONCE() NULL checks on s_encoding in directory lookup and hash paths,
and rejects runtime casefold enablement when CONFIG_UNICODE is disabled.
Link: https://syzbot.org/bug?extid=68178aa1e39c8606392e
Link: https://lore.kernel.org/all/20261202100056.1419-1-zhaimingbing@cmss.chinamobile.com/
> diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
> index 83630cd40712c..515ac455074d2 100644
> --- a/fs/ext4/ioctl.c
> +++ b/fs/ext4/ioctl.c
> @@ -1479,6 +1479,8 @@ static int ext4_validate_tune_sb_params(struct super_block *sb,
> ~le32_to_cpu(es->s_feature_ro_compat);
> if (params->set_feature_incompat_mask &
> EXT4_FEATURE_INCOMPAT_CASEFOLD) {
> + if (!IS_ENABLED(CONFIG_UNICODE))
> + return -EINVAL;
[Severity: Low]
Does this break test_validate_tune_sb_params() in fs/ext4/ioctl-test.c
when CONFIG_EXT4_KUNIT_TESTS is enabled and CONFIG_UNICODE is disabled?
That test unconditionally sets EXT4_FEATURE_INCOMPAT_CASEFOLD and expects
ext4_validate_tune_sb_params_test() to return 0 and default
params.encoding to EXT4_ENC_UTF8_12_1.
> enabling_casefold = 1;
> if (!(params->set_flags & EXT4_TUNE_FL_ENCODING)) {
> params->encoding = EXT4_ENC_UTF8_12_1;
> @@ -1539,6 +1541,7 @@ static int ext4_ioctl_set_tune_sb(struct file *filp,
> struct super_block *sb = file_inode(filp)->i_sb;
> struct ext4_sb_info *sbi = EXT4_SB(sb);
> int ret;
> + bool enabling_casefold;
>
> if (!capable(CAP_SYS_ADMIN))
> return -EPERM;
> @@ -1550,11 +1553,39 @@ static int ext4_ioctl_set_tune_sb(struct file *filp,
> if (ret)
> return ret;
>
> + enabling_casefold = (params.set_flags & EXT4_TUNE_FL_EDIT_FEATURES) &&
> + (params.set_feature_incompat_mask &
> + EXT4_FEATURE_INCOMPAT_CASEFOLD) &&
> + !ext4_has_feature_casefold(sb);
[Severity: Low]
Can two concurrent EXT4_IOC_SET_TUNE_SB_PARAM calls enabling casefold with
different encoding_flags leave sb->s_encoding_flags out of sync with
sbi->s_es->s_encoding_flags?
CPU0 CPU1
ext4_ioctl_set_tune_sb() ext4_ioctl_set_tune_sb()
/* encoding_flags = STRICT */ /* encoding_flags = 0 */
ext4_validate_tune_sb_params() ext4_validate_tune_sb_params()
enabling_casefold = true enabling_casefold = true
ext4_update_superblocks_fn()
es->s_encoding_flags = STRICT
ext4_encoding_init()
sb->s_encoding = encoding
sb->s_encoding_flags = STRICT
ext4_update_superblocks_fn()
es->s_encoding_flags = 0
ext4_encoding_init()
if (READ_ONCE(sb->s_encoding))
return 0; <-- flags not updated
Because validation and enabling_casefold run before any lock is taken,
both callers pass the !ext4_has_feature_casefold(sb) check, and the second
caller overwrites es->s_encoding_flags on disk and in sbi->s_es while
ext4_encoding_init() returns early without updating sb->s_encoding_flags.
> +
> ret = mnt_want_write_file(filp);
> if (ret)
> return ret;
>
> + /* A failed utf8_load() after commit leaves an unmountable fs. */
> + if (enabling_casefold && !READ_ONCE(sb->s_encoding)) {
[Severity: High]
Does this fail to compile when CONFIG_UNICODE is disabled? In
include/linux/fs/super_types.h, struct super_block only defines s_encoding
inside #if IS_ENABLED(CONFIG_UNICODE), whereas ext4_ioctl_set_tune_sb() is
compiled unconditionally.
> + ret = ext4_encoding_probe(sb, params.encoding);
> + if (ret) {
> + mnt_drop_write_file(filp);
> + return ret;
> + }
> + }
> +
> ret = ext4_update_superblocks_fn(sb, ext4_sb_setparams, ¶ms);
> +
> + /* Serialise concurrent callers: only one unicode_map may load. */
> + if (ret == 0 && enabling_casefold) {
[Severity: Medium]
Can setting EXT4_FEATURE_INCOMPAT_CASEFOLD in sbi->s_es before
sb->s_encoding is loaded still leave directories with S_CASEFOLD enabled
while sb->s_encoding is NULL?
ext4_update_primary_sb() invokes ext4_sb_setparams() and sets
EXT4_FEATURE_INCOMPAT_CASEFOLD in sbi->s_es before synchronous primary and
backup superblock I/O and before ext4_encoding_init() runs. In addition,
if ext4_update_superblocks_fn() fails after modifying sbi->s_es (for
example during backup superblock I/O or ext4_journal_stop()), or if the
second utf8_load() allocation in ext4_encoding_init() fails after
ext4_encoding_probe() unloaded the probed map, sbi->s_es retains
EXT4_FEATURE_INCOMPAT_CASEFOLD while sb->s_encoding stays NULL for the
rest of the mount.
Because ext4_fileattr_set() only checks ext4_has_feature_casefold(sb) and
not sb->s_encoding, a directory can be marked EXT4_CASEFOLD_FL
(S_CASEFOLD) while sb->s_encoding is NULL. In that state, the new !um
early return in ext4_fname_setup_ci_filename() returns 0 before computing
name->hinfo on encrypted casefolded directories, and dx_probe(),
make_indexed_dir(), and ext4_insert_dentry() skip ext4fs_dirhash() when
IS_ENCRYPTED(dir) && IS_CASEFOLDED(dir), writing zero hashes into on-disk
dirents and HTree nodes; on unencrypted casefolded directories,
ext4fs_dirhash() and ext4_match() fall back to non-casefolded hashing and
matching, writing non-casefolded hashes and allowing duplicate
case-colliding entries on disk.
> + static DEFINE_MUTEX(casefold_enable_lock);
> +
> + mutex_lock(&casefold_enable_lock);
> + ret = ext4_encoding_init(sb, sbi->s_es);
[Severity: Medium]
If casefold is enabled at runtime here, what installs
generic_ci_dentry_ops on the superblock and existing dentries?
__ext4_fill_super() calls generic_set_sb_d_ops(sb) once at mount time,
which only installs generic_ci_dentry_ops (DCACHE_OP_HASH |
DCACHE_OP_COMPARE) if sb->s_encoding is already non-NULL. When
sb->s_encoding is populated later via ext4_ioctl_set_tune_sb(),
generic_ci_dentry_ops is never installed, so VFS dcache lookups in
S_CASEFOLD directories remain case-sensitive while ext4_lookup() matches
case-insensitively on disk.
Looking up an existing file under a different case misses in the dcache
and calls d_splice_alias(inode, dentry) in ext4_lookup(), creating a
second positive hashed dentry alias for a single-link regular file (so
unlinking one case variant drops i_nlink to 0 while leaving the other
positive dentry hashed in the dcache), mutating live subdirectory dentry
names on read-only lookups of a different case, and bypassing
SB_ENC_STRICT_MODE_FL validation in generic_ci_d_hash().
[ ... ]
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 880f664d6c04b..37431e0ffbfab 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
[ ... ]
> @@ -4772,14 +4772,36 @@ static int ext4_encoding_init(struct super_block *sb, struct ext4_super_block *e
> unicode_rev(encoding_info->version),
> encoding_flags);
>
> - sb->s_encoding = encoding;
> - sb->s_encoding_flags = encoding_flags;
> + /* Order wrt utf8_load() stores inside *encoding */
> + smp_store_release(&sb->s_encoding, encoding);
> + WRITE_ONCE(sb->s_encoding_flags, encoding_flags);
[Severity: Low]
Should WRITE_ONCE(sb->s_encoding_flags, encoding_flags) happen before
smp_store_release(&sb->s_encoding, encoding)?
Readers such as ext4_match() check READ_ONCE(parent->i_sb->s_encoding) and
then read s_encoding_flags via sb_no_casefold_compat_fallback() and
generic_ci_match(). Publishing s_encoding before writing s_encoding_flags
lets a concurrent reader observe a non-NULL s_encoding while
s_encoding_flags is still 0.
--
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_F27193C546272ADCA5A46D593AE4139ABE09@qq.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] ext4: fix NULL s_encoding after runtime tune_sb enables casefold
2026-12-03 1:30 [PATCH v3] ext4: fix NULL s_encoding after runtime tune_sb enables casefold Shuai Liu
2026-12-03 1:47 ` sashiko-bot
@ 2026-12-03 11:40 ` kernel test robot
1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2026-12-03 11:40 UTC (permalink / raw)
To: Shuai Liu, linux-ext4
Cc: oe-kbuild-all, tytso, jack, adilger.kernel, libaokun, ojaswin,
ritesh.list, yi.zhang, djwong, zhaimingbing, linux-fsdevel,
linux-kernel, syzbot+68178aa1e39c8606392e, Shuai Liu
Hi Shuai,
kernel test robot noticed the following build errors:
[auto build test ERROR on tytso-ext4/dev]
[also build test ERROR on linus/master v7.4-rc5 next-20261202]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Shuai-Liu/ext4-fix-NULL-s_encoding-after-runtime-tune_sb-enables-casefold/20261203-093038
base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
patch link: https://lore.kernel.org/r/tencent_F27193C546272ADCA5A46D593AE4139ABE09%40qq.com
patch subject: [PATCH v3] ext4: fix NULL s_encoding after runtime tune_sb enables casefold
config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20261203/20261203190908.N2uDMQlX-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261203/20261203190908.N2uDMQlX-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/20261203190908.N2uDMQlX-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from <command-line>:
fs/ext4/ioctl.c: In function 'ext4_ioctl_set_tune_sb':
>> fs/ext4/ioctl.c:1566:47: error: 'struct super_block' has no member named 's_encoding'
1566 | if (enabling_casefold && !READ_ONCE(sb->s_encoding)) {
| ^~
include/linux/compiler_types.h:682:23: note: in definition of macro '__compiletime_assert'
682 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler_types.h:702:9: note: in expansion of macro '_compiletime_assert'
702 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:9: note: in expansion of macro 'compiletime_assert'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:28: note: in expansion of macro '__native_word'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~
include/asm-generic/rwonce.h:49:9: note: in expansion of macro 'compiletime_assert_rwonce_type'
49 | compiletime_assert_rwonce_type(x); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fs/ext4/ioctl.c:1566:35: note: in expansion of macro 'READ_ONCE'
1566 | if (enabling_casefold && !READ_ONCE(sb->s_encoding)) {
| ^~~~~~~~~
>> fs/ext4/ioctl.c:1566:47: error: 'struct super_block' has no member named 's_encoding'
1566 | if (enabling_casefold && !READ_ONCE(sb->s_encoding)) {
| ^~
include/linux/compiler_types.h:682:23: note: in definition of macro '__compiletime_assert'
682 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler_types.h:702:9: note: in expansion of macro '_compiletime_assert'
702 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:9: note: in expansion of macro 'compiletime_assert'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:28: note: in expansion of macro '__native_word'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~
include/asm-generic/rwonce.h:49:9: note: in expansion of macro 'compiletime_assert_rwonce_type'
49 | compiletime_assert_rwonce_type(x); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fs/ext4/ioctl.c:1566:35: note: in expansion of macro 'READ_ONCE'
1566 | if (enabling_casefold && !READ_ONCE(sb->s_encoding)) {
| ^~~~~~~~~
>> fs/ext4/ioctl.c:1566:47: error: 'struct super_block' has no member named 's_encoding'
1566 | if (enabling_casefold && !READ_ONCE(sb->s_encoding)) {
| ^~
include/linux/compiler_types.h:682:23: note: in definition of macro '__compiletime_assert'
682 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler_types.h:702:9: note: in expansion of macro '_compiletime_assert'
702 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:9: note: in expansion of macro 'compiletime_assert'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:28: note: in expansion of macro '__native_word'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~
include/asm-generic/rwonce.h:49:9: note: in expansion of macro 'compiletime_assert_rwonce_type'
49 | compiletime_assert_rwonce_type(x); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fs/ext4/ioctl.c:1566:35: note: in expansion of macro 'READ_ONCE'
1566 | if (enabling_casefold && !READ_ONCE(sb->s_encoding)) {
| ^~~~~~~~~
>> fs/ext4/ioctl.c:1566:47: error: 'struct super_block' has no member named 's_encoding'
1566 | if (enabling_casefold && !READ_ONCE(sb->s_encoding)) {
| ^~
include/linux/compiler_types.h:682:23: note: in definition of macro '__compiletime_assert'
682 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler_types.h:702:9: note: in expansion of macro '_compiletime_assert'
702 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:9: note: in expansion of macro 'compiletime_assert'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:28: note: in expansion of macro '__native_word'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~
include/asm-generic/rwonce.h:49:9: note: in expansion of macro 'compiletime_assert_rwonce_type'
49 | compiletime_assert_rwonce_type(x); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fs/ext4/ioctl.c:1566:35: note: in expansion of macro 'READ_ONCE'
1566 | if (enabling_casefold && !READ_ONCE(sb->s_encoding)) {
| ^~~~~~~~~
>> fs/ext4/ioctl.c:1566:47: error: 'struct super_block' has no member named 's_encoding'
1566 | if (enabling_casefold && !READ_ONCE(sb->s_encoding)) {
| ^~
include/linux/compiler_types.h:682:23: note: in definition of macro '__compiletime_assert'
682 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler_types.h:702:9: note: in expansion of macro '_compiletime_assert'
702 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:9: note: in expansion of macro 'compiletime_assert'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:49:9: note: in expansion of macro 'compiletime_assert_rwonce_type'
49 | compiletime_assert_rwonce_type(x); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fs/ext4/ioctl.c:1566:35: note: in expansion of macro 'READ_ONCE'
1566 | if (enabling_casefold && !READ_ONCE(sb->s_encoding)) {
| ^~~~~~~~~
>> fs/ext4/ioctl.c:1566:47: error: 'struct super_block' has no member named 's_encoding'
1566 | if (enabling_casefold && !READ_ONCE(sb->s_encoding)) {
| ^~
include/linux/compiler_types.h:635:53: note: in definition of macro '__unqual_scalar_typeof'
635 | #define __unqual_scalar_typeof(x) __typeof_unqual__(x)
| ^
include/asm-generic/rwonce.h:50:9: note: in expansion of macro '__READ_ONCE'
50 | __READ_ONCE(x); \
| ^~~~~~~~~~~
fs/ext4/ioctl.c:1566:35: note: in expansion of macro 'READ_ONCE'
1566 | if (enabling_casefold && !READ_ONCE(sb->s_encoding)) {
| ^~~~~~~~~
In file included from ./arch/x86/include/generated/asm/rwonce.h:1,
from include/linux/compiler.h:394,
from include/linux/export.h:5,
from include/linux/linkage.h:7,
from arch/x86/include/asm/cache.h:5,
from include/vdso/cache.h:5,
from include/linux/cache.h:6,
from include/linux/time.h:5,
from include/linux/stat.h:19,
from include/linux/fs_dirent.h:5,
from include/linux/fs/super_types.h:5,
from include/linux/fs/super.h:5,
from include/linux/fs.h:5,
from fs/ext4/ioctl.c:11:
>> fs/ext4/ioctl.c:1566:47: error: 'struct super_block' has no member named 's_encoding'
1566 | if (enabling_casefold && !READ_ONCE(sb->s_encoding)) {
| ^~
include/asm-generic/rwonce.h:44:73: note: in definition of macro '__READ_ONCE'
44 | #define __READ_ONCE(x) (*(const volatile __unqual_scalar_typeof(x) *)&(x))
| ^
fs/ext4/ioctl.c:1566:35: note: in expansion of macro 'READ_ONCE'
1566 | if (enabling_casefold && !READ_ONCE(sb->s_encoding)) {
| ^~~~~~~~~
vim +1566 fs/ext4/ioctl.c
1536
1537 static int ext4_ioctl_set_tune_sb(struct file *filp,
1538 struct ext4_tune_sb_params __user *in)
1539 {
1540 struct ext4_tune_sb_params params;
1541 struct super_block *sb = file_inode(filp)->i_sb;
1542 struct ext4_sb_info *sbi = EXT4_SB(sb);
1543 int ret;
1544 bool enabling_casefold;
1545
1546 if (!capable(CAP_SYS_ADMIN))
1547 return -EPERM;
1548
1549 if (copy_from_user(¶ms, in, sizeof(params)))
1550 return -EFAULT;
1551
1552 ret = ext4_validate_tune_sb_params(sb, ¶ms);
1553 if (ret)
1554 return ret;
1555
1556 enabling_casefold = (params.set_flags & EXT4_TUNE_FL_EDIT_FEATURES) &&
1557 (params.set_feature_incompat_mask &
1558 EXT4_FEATURE_INCOMPAT_CASEFOLD) &&
1559 !ext4_has_feature_casefold(sb);
1560
1561 ret = mnt_want_write_file(filp);
1562 if (ret)
1563 return ret;
1564
1565 /* A failed utf8_load() after commit leaves an unmountable fs. */
> 1566 if (enabling_casefold && !READ_ONCE(sb->s_encoding)) {
1567 ret = ext4_encoding_probe(sb, params.encoding);
1568 if (ret) {
1569 mnt_drop_write_file(filp);
1570 return ret;
1571 }
1572 }
1573
1574 ret = ext4_update_superblocks_fn(sb, ext4_sb_setparams, ¶ms);
1575
1576 /* Serialise concurrent callers: only one unicode_map may load. */
1577 if (ret == 0 && enabling_casefold) {
1578 static DEFINE_MUTEX(casefold_enable_lock);
1579
1580 mutex_lock(&casefold_enable_lock);
1581 ret = ext4_encoding_init(sb, sbi->s_es);
1582 mutex_unlock(&casefold_enable_lock);
1583 if (ret)
1584 ext4_msg(sb, KERN_ERR,
1585 "runtime tune_sb: encoding_init failed (%d)",
1586 ret);
1587 }
1588
1589 mnt_drop_write_file(filp);
1590
1591 if (params.set_flags & EXT4_TUNE_FL_DEF_HASH_ALG)
1592 sbi->s_def_hash_version = params.def_hash_alg;
1593
1594 return ret;
1595 }
1596
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-03 11:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 1:30 [PATCH v3] ext4: fix NULL s_encoding after runtime tune_sb enables casefold Shuai Liu
2026-12-03 1:47 ` sashiko-bot
2026-12-03 11:40 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox