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=1796086672; b=icZJyD5DssBe5k/A3smvv9IlbTsNrjHpvrUYy2YbC+zsR2pAFm5S9kybCAdP244qhoYh J/cJSWTzSbYK1tll4eHqi8XzzEnFWbv1epCRDMUEh6N1l7fbqFAU+rrOVeFr2mBwtBfF7 BTMAu3OvemiNY7pHV3997NtToqE/GMlfOUoE1I9tuqpijl99dwPrFWJj7fY86KkzrBoSj 4XU9JpVM8rt7sd+dt/4gwfW4BVbbKbrFHk2UsTDdfP9e8tpsXfmzB6bGxj41Wcb3qCki/ dItLIZPhd8er6WguQH4lm6fNOAuruyvUBwKpKoRaR4u523YuUTCm6O18T3XK2cJIo+w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796086672; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=COnrccV28nI37+UFHq7bJqPlQ2dxAHKL7o6m2r8FOZ0=; b=vWHPix5tTdCn/ug/NtzCYcoq47DJ9buEO5kkX+PwHWsZSdd8TIau6OwFQ+1K+3Mpiu2A WcwsS5Cm5NRRX9FMKnxp+TKccX/brALrH7LNfZ9EOmXdyb0hbubtAPqN365q83Jt4dwYy EnttDg5CTcUonov7bweNSwl2oBR8DoPV8jHn53yclvytXnwShNQ0O1g4+8AXoSLhZeV4w ppeUM9b5ux/bOKrK6vRr0Ar++/YrdWYjP6bACc/eTM04Wx/ia7fXotgl8rXpRKVpLZbNm XNMHQQPzUC4XcNfbvDESXiZqt3iS5ifRTwj8KcpOQ/Kryy4l7184eitEdCV3Pr4epsA== 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=dturojnJ; 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 0BFF6606A31A for ; Tue, 1 Dec 2026 00:57:52 +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=dturojnJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFF661F00893; Tue, 1 Dec 2026 00:57:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796086671; bh=COnrccV28nI37+UFHq7bJqPlQ2dxAHKL7o6m2r8FOZ0=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=dturojnJTcmGNC7zn7jz0SqNoli2jQF8puXa+krp2SJDJXReW7yY1ia5wyLtFCJ9r 2MrnYc+Kca9bsi5C+il6dcL0MBTIcrcc4F1AkDdpwMlcauphIRZVuaoSPJlszx+cPI Iv0ABnYOzNnVB8I7RwfCxldkaLM9CV7EibgZNJjKqKl87jj0OfiWeqAvLZx2VFPa6b O/Csbtdz+k0UVlaoIanCE6GtXETzOy/f/uestQwYV9capL0xnQe0FErQOoAaLC+zZ+ J0og5gU6QY5/5HX71N3M3yCBYZAx2EULlVEGcebLBPN5kJTXhRC1cX/8gJdKDV+8DE NdG4MJY/B4toA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] ext4: fix NULL s_encoding after runtime tune_sb enables casefold Reply-To: sashiko-reviews@lists.linux.dev To: "Shuai Liu" <847807867@qq.com> Cc: linux-ext4@vger.kernel.org, tytso@mit.edu In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 00:57:51 +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: - [Medium] ext4: NULL s_encoding dereference in ext4_match() via generic_ci_match() - [Medium] ext4: unlocked runtime ext4_encoding_init() in ext4_ioctl_set_tune_sb() - [Medium] ext4: racy s_encoding reads in ext4fs_dirhash() and ext4_encoding_init() - [Medium] ext4: runtime casefold enablement in ext4_ioctl_set_tune_sb() misses d_op - [Low] ext4: missing Fixes trailer for commit 04a91570ac67 -- commit a997535bd70f67593a441110fc016309b4deca29 Author: Shuai Liu <847807867@qq.com> > ext4: fix NULL s_encoding after runtime tune_sb enables casefold >=20 > 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. >=20 > 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 (the tune_sb validation passes), and any lookup > in that directory calls ext4_fname_setup_ci_filename() which invokes > utf8_casefold(dir->i_sb->s_encoding, ...) with a NULL um pointer. >=20 > Reproducer trace from syzbot: > mount(ext4) =E2=86=92 EXT4_IOC_SET_TUNE_SB_PARAM(enables casefold) =E2= =86=92 > mkdir =E2=86=92 FS_IOC_SETFLAGS(FS_CASEFOLD_FL) =E2=86=92 open triggers= lookup =E2=86=92 > utf8_casefold(NULL, ...) =E2=86=92 utf8nlookup+0x39 NULL ptr deref =E2= =86=92 GPF >=20 > Fix: call ext4_encoding_init() after the tune_sb update succeeds so > sb->s_encoding gets loaded at runtime, mirroring what happens during > mount. If encoding_init fails for an unexpected reason (e.g. an > unsupported encoding version) we print a warning but do not roll > back the already-committed superblock change. >=20 > Also add defensive NULL checks at both callers that dereference > s_encoding (ext4_fname_setup_ci_filename and ext4fs_dirhash) so any > future code path that enables casefold without loading encoding wont > crash. The defensive checks let the casefold path safely fall back > to the non-casefold code when s_encoding is missing. >=20 > The ext4_encoding_init() stub was previously defined as static inline in > super.c for CONFIG_UNICODE=3Dn. Move the stub declaration into ext4.h so = it > is available to callers in other translation units. >=20 > Link: https://syzbot.org/bug?extid=3D68178aa1e39c8606392e > Reported-by: syzbot+68178aa1e39c8606392e@syzkaller.appspotmail.com > Closes: https://syzbot.org/bug?extid=3D68178aa1e39c8606392e > Signed-off-by: Shuai Liu <847807867@qq.com> [Severity: Low] This fixes a bug in runtime superblock tuning. Should it include: Fixes: 04a91570ac67 ("ext4: implemet new ioctls to set and get superblock= parameters") [ ... ] > diff --git a/fs/ext4/hash.c b/fs/ext4/hash.c > index 978bd92da0ad3..981eb087ec2b0 100644 > --- a/fs/ext4/hash.c > +++ b/fs/ext4/hash.c > @@ -321,6 +321,7 @@ int ext4fs_dirhash(const struct inode *dir, const cha= r *name, int len, > struct qstr qstr =3D {.name =3D name, .len =3D len }; > =20 > if (len && IS_CASEFOLDED(dir) && > + dir->i_sb->s_encoding && > (!IS_ENCRYPTED(dir) || fscrypt_has_encryption_key(dir))) { > buff =3D kzalloc(PATH_MAX, GFP_KERNEL); > if (!buff) [Severity: Medium] Can ext4fs_dirhash() still pass a NULL um to utf8_casefold() when dir->i_sb->s_encoding is initialized concurrently at runtime? ext4fs_dirhash() loads um =3D dir->i_sb->s_encoding on entry, then re-reads dir->i_sb->s_encoding in the condition above before calling utf8_casefold(um, ...): CPU0 CPU1 ext4fs_dirhash() um =3D dir->i_sb->s_encoding; (NULL) ext4_ioctl_set_tune_sb() ext4_encoding_init() sb->s_encoding =3D encoding; if (... && dir->i_sb->s_encoding) utf8_casefold(um, ...) <-- NULL pointer dereference ext4_encoding_init() also writes sb->s_encoding before sb->s_encoding_flags without release ordering, so concurrent readers on a live mount can observe a non-NULL sb->s_encoding before sb->s_encoding_flags is visible. > diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c > index 83630cd40712c..7830089413b31 100644 > --- a/fs/ext4/ioctl.c > +++ b/fs/ext4/ioctl.c > @@ -1557,6 +1557,15 @@ static int ext4_ioctl_set_tune_sb(struct file *fil= p, > ret =3D ext4_update_superblocks_fn(sb, ext4_sb_setparams, ¶ms); > mnt_drop_write_file(filp); > =20 > + if (ret =3D=3D 0) { > + int enc_ret =3D ext4_encoding_init(sb, sbi->s_es); > + > + if (enc_ret < 0) > + ext4_msg(sb, KERN_WARNING, > + "runtime tune_sb: encoding_init failed (%d)", > + enc_ret); > + } > + > if (params.set_flags & EXT4_TUNE_FL_DEF_HASH_ALG) > sbi->s_def_hash_version =3D params.def_hash_alg; > =20 [Severity: Medium] Can concurrent EXT4_IOC_SET_TUNE_SB_PARAM calls race in ext4_encoding_init() and leak a struct unicode_map and a utf8_data_table module reference? ext4_encoding_init() runs after ext4_update_superblocks_fn() has cleared EXT4_FLAGS_RESIZING and mnt_drop_write_file() has dropped write access. Because ext4_encoding_init() checks !sb->s_encoding without a lock and then sleeps in utf8_load(), two callers can both pass the check and overwrite sb->s_encoding, leaking the first encoding and its symbol_request() reference on unmount. In addition, ext4_update_primary_sb() sets EXT4_FEATURE_INCOMPAT_CASEFOLD in sbi->s_es before backup superblocks are updated, so if a backup update or journal stop fails (ret !=3D 0), ext4_encoding_init() is skipped even though casefold is already enabled in sbi->s_es. [Severity: Medium] Does enabling casefold at runtime leave generic_ci_dentry_ops unset on the superblock and existing cached dentries? At mount time, __ext4_fill_super() calls generic_set_sb_d_ops(sb), which installs generic_ci_dentry_ops only if sb->s_encoding is already non-NULL. When sb->s_encoding is populated later via ext4_ioctl_set_tune_sb(), sb->__s_d_op and existing dentries lack DCACHE_OP_HASH | DCACHE_OP_COMPARE, so VFS dcache lookups remain case-sensitive while ext4_lookup() matches case-insensitively on disk, creating duplicate positive dentries with different casing for the same inode and bypassing strict encoding checks in generic_ci_d_hash(). > diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c > index b2753daad49f4..385e6d0bda98f 100644 > --- a/fs/ext4/namei.c > +++ b/fs/ext4/namei.c > @@ -1214,6 +1214,7 @@ int ext4_fname_setup_ci_filename(struct inode *dir,= const struct qstr *iname, > int len; > =20 > if (!IS_CASEFOLDED(dir) || > + !dir->i_sb->s_encoding || > (IS_ENCRYPTED(dir) && !fscrypt_has_encryption_key(dir))) { > cf_name->name =3D NULL; > return 0; [Severity: Medium] When dir->i_sb->s_encoding is NULL on a casefolded directory (for example, when ext4_encoding_init() fails and logs the warning above), does lookup still dereference a NULL s_encoding in ext4_match() -> generic_ci_match()? Returning 0 here with cf_name->name =3D NULL lets __ext4_find_entry() continue into ext4_search_dir() -> ext4_match(): fs/ext4/namei.c:ext4_match() { ... if (IS_CASEFOLDED(parent) && (!IS_ENCRYPTED(parent) || fscrypt_has_encryption_key(parent))) { ... return generic_ci_match(parent, fname->usr_fname, &fname->cf_name, de->name, de->name_len) > 0; } ... } Because ext4_match() does not check parent->i_sb->s_encoding, and fname->cf_name.name is NULL, generic_ci_match() falls back to utf8_strncasecmp(parent->i_sb->s_encoding, ...) on the first entry ('.') and dereferences NULL in utf8nlookup(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/tencent_A8E6DCBBA41= 55872E5A59BFE7031C49E2709@qq.com?part=3D1