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=1796262475; b=lyq5/ZUtpIv5aBKatzbVZLSKQbqbm76N+HpKS7WbSP/YQY/U9NGjzk2Uch3MRKH84DVz QC21ej9muEkJ4EI6VeWPZu4CTGhTs6Bb8A3JXco6wzNQurCiAUv3TC/57Vqhf8/RacJ3s 40AK2cCBJew/l+RnciqPhaI1OJ4kuYvLHtnMnWw9NIV0kOBJP8Z8+lTRNDBQpCaRYP3B6 9zdFfSRGOzr63ojhXognWHVOFnPKDcQDrA7JPo/KLoxURUCTieNqM8ZC81f09CqOKEXLc NqYVGqh9suUngXlYnmgGwPOaxjryOszLYDvhMny7JvP12GkQIynroD/WG4yicS7US/g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796262475; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=0pQjOMq9bsliTol1CyNQYCMt9oy4S1z5ZzRO/xgjiCs=; b=pLuKlLSpEtz3V8YQnl/lfG73/WyPe4vYthxI3szuR4VvofRIAgeps9OoF4j/ye+u0rZd O5Dhi2cREqEqV5lAUyyvsQxqm81UDIHVCOxvX28EMs21h/N4DNlsNMt1pkQmeshJzwjxb QWPXVbEmpsuc1suUv5+8boUhb3nhZqf0v/Zz9720N0gSl8bJCU1BpgfOt0pI43hlChZv0 OdDnIhQdx29eOImmFxoSetYRCPYSJXYwwXDy6FJqO4+ttqZg+WeiAi0v+tI3CgN8drCG+ 7JV2DAMnm1o+/asivIXzBczbQho6WIGHk2atZi9MU9AwMdVsnpTQkwu4QhuAYl2zlMw== 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=ZfocReiM; 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 F0A09606A322 for ; Thu, 3 Dec 2026 01:47:54 +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=ZfocReiM Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65F8C1F000C1; Thu, 3 Dec 2026 01:47:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796262474; bh=0pQjOMq9bsliTol1CyNQYCMt9oy4S1z5ZzRO/xgjiCs=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=ZfocReiMdOg81071Qwyq4TCFJFf5Q/xSAYX+vsugm/NSPapGqaefp6sRU4WQ2Bfzw SL7GuueYSWLTTqJLm0mYnRPwcx08NdybvQN+O7pM/35DhsQKmrajashbsW+6t8fs18 7vIB7ByG+o2UOuaqjGuI4c4KYaOkbJw4e3ZvFAePq0/JVd9/nMQpCD0ghc5Cuwa0yY J0WbHoCPDO/6jvjYy6VGvF2r2X+qgutRuGuMqT2JmTHT0IMWFRMfzqwcMLrP8bfr9u eMg7DlwBy53lz7HBxwN5hE/fLh0GCZyiGx3lhis5J1x0UrtmnPsf6GHvsRwVdku77I SlKR+cWc4m9Cg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3] ext4: fix NULL s_encoding after runtime tune_sb enables casefold Reply-To: sashiko-reviews@lists.linux.dev To: "Shuai Liu" <847807867@qq.com>, linux-ext4@vger.kernel.org Cc: tytso@mit.edu In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 01:47:54 +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 6 potential issues to consider: - [High] ext4: build failure in ext4_ioctl_set_tune_sb() when CONFIG_UNICODE=3Dn - [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=3Dn - [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=3D68178aa1e39c8606392e Link: https://lore.kernel.org/all/20261202100056.1419-1-zhaimingbing@cmss.c= hinamobile.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 supe= r_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 =3D 1; > if (!(params->set_flags & EXT4_TUNE_FL_ENCODING)) { > params->encoding =3D EXT4_ENC_UTF8_12_1; > @@ -1539,6 +1541,7 @@ static int ext4_ioctl_set_tune_sb(struct file *filp, > struct super_block *sb =3D file_inode(filp)->i_sb; > struct ext4_sb_info *sbi =3D EXT4_SB(sb); > int ret; > + bool enabling_casefold; > =20 > if (!capable(CAP_SYS_ADMIN)) > return -EPERM; > @@ -1550,11 +1553,39 @@ static int ext4_ioctl_set_tune_sb(struct file *fi= lp, > if (ret) > return ret; > =20 > + enabling_casefold =3D (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 =3D STRICT */ /* encoding_flags =3D 0 */ ext4_validate_tune_sb_params() ext4_validate_tune_sb_params() enabling_casefold =3D true enabling_casefold =3D true ext4_update_superblocks_fn() es->s_encoding_flags =3D STRICT ext4_encoding_init() sb->s_encoding =3D encoding sb->s_encoding_flags =3D STRICT ext4_update_superblocks_fn() es->s_encoding_flags =3D 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 =3D mnt_want_write_file(filp); > if (ret) > return ret; > =20 > + /* 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 =3D ext4_encoding_probe(sb, params.encoding); > + if (ret) { > + mnt_drop_write_file(filp); > + return ret; > + } > + } > + > ret =3D ext4_update_superblocks_fn(sb, ext4_sb_setparams, ¶ms); > + > + /* Serialise concurrent callers: only one unicode_map may load. */ > + if (ret =3D=3D 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 =3D 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); > =20 > - sb->s_encoding =3D encoding; > - sb->s_encoding_flags =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/tencent_F27193C5462= 72ADCA5A46D593AE4139ABE09@qq.com?part=3D1