Linux EXT4 FS development
 help / color / mirror / Atom feed
* [PATCH] ext4: load the casefold encoding when it is enabled online
@ 2026-12-02 10:00 Mingbing Zhai
  2026-12-02 10:16 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Mingbing Zhai @ 2026-12-02 10:00 UTC (permalink / raw)
  To: tytso
  Cc: adilger.kernel, libaokun, jack, ojaswin, ritesh.list, yi.zhang,
	linux-ext4, linux-kernel, stable, yangguikun19,
	syzbot+68178aa1e39c8606392e, Mingbing Zhai

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
---
 fs/ext4/ext4.h  |  9 +++++++++
 fs/ext4/ioctl.c | 11 +++++++++++
 fs/ext4/super.c |  7 +------
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index dc2c181337a16..001b95a78cfff 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -3494,6 +3494,15 @@ extern int ext4_convert_meta_bg_test(struct super_block *sb,
 #endif
 
 /* super.c */
+#if IS_ENABLED(CONFIG_UNICODE)
+int ext4_encoding_init(struct super_block *sb, struct ext4_super_block *es);
+#else
+static inline int ext4_encoding_init(struct super_block *sb,
+				      struct ext4_super_block *es)
+{
+	return 0;
+}
+#endif
 extern struct buffer_head *ext4_sb_bread(struct super_block *sb,
 					 sector_t block, blk_opf_t op_flags);
 extern struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb,
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;
@@ -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, &params);
+
+	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);
 
 	if (params.set_flags & EXT4_TUNE_FL_DEF_HASH_ALG)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 880f664d6c04b..9cdf610293dfe 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -4737,7 +4737,7 @@ 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;
@@ -4777,11 +4777,6 @@ static int ext4_encoding_init(struct super_block *sb, struct ext4_super_block *e
 
 	return 0;
 }
-#else
-static inline int ext4_encoding_init(struct super_block *sb, struct ext4_super_block *es)
-{
-	return 0;
-}
 #endif
 
 static int ext4_init_metadata_csum(struct super_block *sb, struct ext4_super_block *es)
-- 
2.43.0




^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-02 10:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox