From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796206568; b=i549Ngyock7CImHnCl8Q+aoMiTv/6GhvC3u++MBet28xCcFwx1PzJY+DTL1nuQpkSpp6 d6k9nPsMS46mrjdQb2kVNFXNB2rK4ZlsCh7kMob0lX1m1NmzHEY0WPH00QbY6dDKRSMyG /6TTNgYaqnuZ03f3hzmLxrsgx7Rzy3t7URgeIfPpG2ROKGa160Hm7RQZhgBJoDVEz4d97 hMxsQT3P46UCrUPLXCDLmpI/INRRYZI0ruJYpAYi3ecyCpk3CkLao139Ggh04dnMpVOCd 3p4p5gwoLpj3UKzeHgZGYdIzEFDwhPztDNGnWjDhvOY3L8kUtcKJQgNQcJZcOcYWijw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796206568; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=UVzGg/4ZRMVytLT+Lg5NeHCw7KPjrS7J4gyfX0dN7y8=; b=hsx7Dv9UwB4UC/hYB3cSG+Hozqh++KWgSkNMORbfxLbTBKWmvS9jCQzPb8LJ0lE899rS slxSW4B/G9dRblV39uelHSNpJ/+hDjo05XMQhxW1xoJ9iYVFEykEh29ucDpapoRwsbr94 AVXRz+PBk7jqE72hcSPHIl7i7o0B/OwanPiH3xovgvkTJK/FBrKRXkTiOoCDdikrZpPGA mZgrA/z9Vv9ZlvbwPA9VFhh2tHXsHvpjSyBg0H380MbL/6/Js8EAC8XXjW5I+vX7h2tjB 4fKyTkkLmJ8qjAxM49hBWAoVrifBPOw7khYCBd4l+L3gyiuTgFlEj9QqMmyS0GVOVUA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QNPurrgq; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC632606A329 for ; Wed, 2 Dec 2026 10:16:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QNPurrgq Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BC771F0089B; Wed, 2 Dec 2026 10:16:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796206568; bh=UVzGg/4ZRMVytLT+Lg5NeHCw7KPjrS7J4gyfX0dN7y8=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=QNPurrgqsRgiOsSdb/08yLYOitvbQkircbILfo0eMEfaWp3pzi31/QdJ46VT2I29U Tf7eZ33PWJfICne5mKtVYyKEkuuAoo6GDGg6HkVO9/XRRh8ZcgtepBcivgonZ3vAw7 rpivFS8igv/oj299hAQNweIjsyPjDjCSTW4pdqyLpSgwaLN0XEgEpmIPkObbVVqeX4 +DakZfynILCJoEw/8HwBr31RfCa/ZWOpfsAC8GZvbQ4O9DFTjogv61DSIBZgMAT6qE cG3xk39Ink7CYXcqzhgiSN2Vu+AW37VKGdnJEQ4YDrXlbWtFEL1+lC0o/+leUxV0Ip Xo8HF5p0eP/mA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] ext4: load the casefold encoding when it is enabled online Reply-To: sashiko-reviews@lists.linux.dev To: "Mingbing Zhai" Cc: linux-ext4@vger.kernel.org, tytso@mit.edu In-Reply-To: <20261202100056.1419-1-zhaimingbing@cmss.chinamobile.com> References: <20261202100056.1419-1-zhaimingbing@cmss.chinamobile.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 10:16:07 +0000 X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 > 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=3D68178aa1e39c8606392e > Reported-by: Guikun Yang > Link: https://lore.kernel.org/r/tencent_B079992E4541FB5447D9A4067D6F8D403= 80A@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 supe= r_block *sb, > if (params->set_feature_incompat_mask & > EXT4_FEATURE_INCOMPAT_CASEFOLD) { > enabling_casefold =3D 1; > + if (!IS_ENABLED(CONFIG_UNICODE)) > + return -EOPNOTSUPP; > if (!(params->set_flags & EXT4_TUNE_FL_ENCODING)) { > params->encoding =3D EXT4_ENC_UTF8_12_1; > params->set_flags |=3D 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 =3D EXT4_TUNE_FL_EDIT_FEATURES; params.set_feature_incompat_mask =3D 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 *fil= p, > return ret; > =20 > ret =3D 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 =3D ext4_encoding_init(sb, sbi->s_es); > + > + if (err && !ret) > + ret =3D 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 =3D &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 =3D 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 =3D=3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202100056.1419= -1-zhaimingbing@cmss.chinamobile.com?part=3D1