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=1796173530; b=lwRg51k1QwMOVFcmiP4YXEjjlH+ucNDpC8DP0XfQOF7xZ6qyFD4Ryt1/0j2fIcHry222 OjnbyByLK/lVkXD/Cnnyk405UvxIUdC6DjWsXClJa9ppbCT5llVmPDS6QlfV+wvwSqQPy TRYgE5jzGQirTqe+SrI/mDWevQdbmGZhMmgguEQ93esIONCa09tVIiKg7KR3jhF8uBnm3 sRnhlckOsqSX23cw8xpefqx03Nj+04R+lLyH2TKsPPMU+yOjMGdP5J1SBBgm+2VqOMC1E 72VF5suQA21MbMkpuI6S3GE1fErmv3gHCknDSGqzE9qP6FRKPajMLsxCCIKWd9vUFKQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796173530; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=5xPYCuvTq9rLz1VN/MAHAT/RjBbDw6umqyR+r+BufiY=; b=JBUdetTdgf6Xpz71rToL6GxoxIawA6a0zPRUyrMn0o6pAlvqZDnibZg9c1iWnPh4LX4D L0fsdU/rvV66d3T/1086ZsKZX3hxL9eYe7G8Ij+HHr1OLZWDkMp7EZCPvKxKeVye+J1J9 FL87wzSD/XVKotjfmXY9BZDDm0iV+Uancp81gJfL16PYNTZDS9b6y8M9GAaq8UCyHALyk HSTSzy9HUjIpIKcysTlT373L8WpNcNZDWOW0SzVzLLEGXCZdCqgVV7uoy/QUabTFAR5Jm i9fgG7t+PFRhB1XQEe0GwBLu8pJQ+nvJc5m1ZTxT9c/vyqjsdWD42l26LUPDyEaDgnA== 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=CIjGaS76; 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 AD577606A31A for ; Wed, 2 Dec 2026 01:05:30 +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=CIjGaS76 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 278421F000C1; Wed, 2 Dec 2026 01:05:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796173530; bh=5xPYCuvTq9rLz1VN/MAHAT/RjBbDw6umqyR+r+BufiY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=CIjGaS76wnFMDb/s/KepsKy4NtSWZBqinKt26BjiJjarNWMh270PCNyhfN9N8gUOH yc8qTGwHNf5JxtO5qVhTZdrYWgzPnPF4XGy3F1cOOUIj4Ritrh9x9z5DKUO+kmfCwv 9npwMGgFFjxvfBeBuDIK1z+znKZPEplZFbLhYzPxyrllg/BX89LBcMTd79fGFL/TiQ O1IVj2sklXyzqqgvJNHNYiqmlI95JvjpFH/JZmQdG57xfVADVVgY+yI1yG4r+RD+qg 6gvOl3hQwsejJh436/9JNKTLgSdMs5nWCgDHXJVavQd78KkInc8YATZxNaEmq1dPio KY4+6NLjzg6Uw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] 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: Wed, 02 Dec 2026 01:05:29 +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 4 potential issues to consider: - [Medium] ext4: runtime generic_set_sb_d_ops() in ext4_ioctl_set_tune_sb() is unsafe - [Medium] ext4: unlocked runtime ext4_encoding_init() leaks unicode_map on race - [Medium] ext4: ext4_ioctl_set_tune_sb() enables casefold before ext4_encoding_init() - [Medium] ext4: missing release barrier and wrong store order in ext4_encoding_init() -- commit 08b106acc329f726b3be87d27b4e362cf818a35a Author: Shuai Liu <847807867@qq.com> ext4: fix NULL s_encoding after runtime tune_sb enables casefold This commit initializes sb->s_encoding and default dentry operations when EXT4_IOC_SET_TUNE_SB_PARAM enables the casefold feature at runtime, and adds NULL checks for s_encoding in the directory hashing and lookup paths. Link: https://syzbot.org/bug?extid=3D68178aa1e39c8606392e [ ... ] > diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c > index 83630cd40712c..b661a6bea2ff1 100644 > --- a/fs/ext4/ioctl.c > +++ b/fs/ext4/ioctl.c > @@ -1555,6 +1555,33 @@ 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 (ret =3D=3D 0) { > + int enc_ret; > + > + /* > + * Call ext4_encoding_init() before mnt_drop_write_file() > + * so that the in-memory s_encoding is established while > + * we still hold the write barrier. This prevents the > + * window where ext4_has_feature_casefold() returns true > + * but sb->s_encoding is still NULL. > + */ > + 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); [Severity: Medium] Can concurrent EXT4_IOC_SET_TUNE_SB_PARAM calls race in ext4_encoding_init() and leak a struct unicode_map and its utf8_data_table module reference? ext4_update_superblocks_fn() clears EXT4_FLAGS_RESIZING before returning, and mnt_want_write_file() only takes a shared freeze-protection counter. Two callers can both pass the unlocked READ_ONCE(sb->s_encoding) check in ext4_encoding_init(), sleep in utf8_load(), and overwrite sb->s_encoding, leaking the first unicode_map and symbol_request(utf8_data_table) reference because ext4_put_super() only unloads sb->s_encoding once. [Severity: Medium] Does enabling EXT4_FEATURE_INCOMPAT_CASEFOLD before ext4_encoding_init() still leave sb->s_encoding as NULL while ext4_has_feature_casefold(sb) is true? mnt_want_write_file() does not block concurrent operations, so ext4_has_feature_casefold(sb) becomes true as soon as ext4_update_primary_sb() updates sbi->s_es. Moreover, sb->s_encoding remains permanently NULL after casefold is committed to sbi->s_es if ext4_encoding_init() fails (which only logs a warning), if ext4_update_superblocks_fn() fails after updating the primary superblock, or if CONFIG_UNICODE is disabled (where ext4_validate_tune_sb_params() still allows setting EXT4_FEATURE_INCOMPAT_CASEFOLD and the ext4_encoding_init() stub returns 0). Because ext4_fileattr_set() only checks ext4_has_feature_casefold(sb), directories can then be marked with EXT4_CASEFOLD_FL while sb->s_encoding is NULL. On an encrypted casefolded directory with a key, the new !um early return in ext4_fname_setup_ci_filename() skips computing name->hinfo, while dx_probe(), make_indexed_dir(), and ext4_insert_dentry() assume fname->hinfo was precomputed and write zero hashes into on-disk directory entries and HTree nodes. > + > + /* > + * After runtime casefold enablement, switch the default > + * dentry operations so that newly created dentries > + * perform case-insensitive VFS dcache lookups. > + */ > + if (IS_ENABLED(CONFIG_UNICODE) && > + ext4_has_feature_casefold(sb)) > + generic_set_sb_d_ops(sb); > + } [Severity: Medium] Can calling generic_set_sb_d_ops() on a live superblock race with __d_alloc() and cause a NULL pointer dereference on path lookup? generic_set_sb_d_ops() is a mount-time helper meant to run before sb->s_root is created. It calls set_default_d_op(sb, &generic_ci_dentry_ops), which updates s->__s_d_op and s->s_d_flags with plain unsynchronized stores while concurrent lookups run __d_alloc(): CPU0 CPU1 ext4_ioctl_set_tune_sb() __d_alloc() generic_set_sb_d_ops(sb) set_default_d_op(sb, ...) dentry->d_op =3D sb->__s_d_op; s->__s_d_op =3D ops; s->s_d_flags =3D ... | flags; dentry->d_flags =3D sb->s_d_flags; ... link_path_walk() parent->d_op->d_hash(...) <-- NULL pointer dereference Before casefold is enabled, sb->__s_d_op is either NULL or &generic_encrypted_dentry_ops (where .d_hash and .d_compare are NULL). If __d_alloc() pairs the old sb->__s_d_op with the new sb->s_d_flags (DCACHE_OP_HASH | DCACHE_OP_COMPARE), later lookups under that directory dereference a NULL d_op or d_hash/d_compare pointer. In addition, VFS lookups test DCACHE_OP_HASH and DCACHE_OP_COMPARE on the parent directory dentry, so any directory already cached before the ioctl (such as sb->s_root) keeps its old d_flags, allowing duplicate positive dentries with different case for the same inode and bypassing generic_ci_d_hash() strict encoding checks. [ ... ] > diff --git a/fs/ext4/super.c b/fs/ext4/super.c > index 880f664d6c04b..8e466a7c14e5b 100644 > --- a/fs/ext4/super.c > +++ b/fs/ext4/super.c > @@ -4772,16 +4773,15 @@ 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; > + /* > + * Publish s_encoding_flags before s_encoding so that concurrent > + * readers either see both old values or both new values. > + */ > + WRITE_ONCE(sb->s_encoding_flags, encoding_flags); > + WRITE_ONCE(sb->s_encoding, encoding); > =20 > return 0; > } [Severity: Medium] Can publishing sb->s_encoding with WRITE_ONCE() instead of smp_store_release() allow readers on weakly-ordered architectures to dereference uninitialized fields of *encoding? WRITE_ONCE() emits no CPU memory barrier, so the store to sb->s_encoding can be observed before the stores in utf8_load() that initialize encoding->tables and encoding->ntab[], causing a lockless READ_ONCE(dir->i_sb->s_encoding) reader in utf8_casefold() -> utf8nlookup() to dereference a NULL pointer. Also, publishing s_encoding_flags before s_encoding when SB_ENC_STRICT_MODE_FL is set allows generic_ci_validate_strict_name() to observe sb_has_strict_encoding(dir->i_sb) as true while dir->i_sb->s_encoding is still NULL: include/linux/fs.h:generic_ci_validate_strict_name() { if (!IS_CASEFOLDED(dir) || !sb_has_strict_encoding(dir->i_sb)) return true; ... if (WARN_ON_ONCE(!dir->i_sb->s_encoding)) return true; } That triggers WARN_ON_ONCE() and returns true without validating the filename in __ext4_add_entry(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/tencent_3040B83162C= 313DDEEB5D2112CF0F2F34D08@qq.com?part=3D1